Skip to content

Commit

Permalink
Added flash messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubujka committed Jan 10, 2012
1 parent fef174c commit e4fb5a7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions cards
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require "file_mode.rb"
require "fileutils.rb"
require "lib/def.rb"
require "lib/bind.rb"
require "lib/flash.rb"

Dir.glob(File.dirname(__FILE__) + '/commands/*', &method(:require))

Expand Down
7 changes: 5 additions & 2 deletions commands/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

doc "Удалить файл и перейти к случайному"
file_cmd :rm_file_and_go_rnd do |file|
flash_s "Deleted: #{file.green}"
File::unlink(file)
if !files_in_pth(dir = File.dirname(file)).empty?
goto_file_mode random_file_in(dir)
Expand All @@ -72,7 +73,8 @@
dir = dirname(file)
clear
if dest = dmenu(dirs_in_pth(dir))
safe_mv(file, fjoin(dir, dest))
safe_mv(file, t = fjoin(dir, dest))
flash_s "File #{file.green} moved to #{t.green}"
if rnd = random_file_in(dir)
goto_file_mode rnd
else
Expand All @@ -86,7 +88,8 @@
dir = fjoin(dirname(file), '..').ex
clear
if dest = dmenu(dirs_in_pth(dir))
safe_mv(file, fjoin(dir, dest))
safe_mv(file, t = fjoin(dir, dest))
flash_s "File #{file.green} moved to #{t.green}"
if rnd = random_file_in(dirname(file))
goto_file_mode rnd
else
Expand Down
1 change: 1 addition & 0 deletions dir_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def default_dir_action dir

def do_what_i_say_in_dir dir
nl
print_flash_messages
print "What to do:".green

if cmd = get_cmd_from_user
Expand Down
1 change: 1 addition & 0 deletions file_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def default_file_action file

def do_what_i_say_in_file file
nl
print_flash_messages
print "What to do:".green

dir = dirname file
Expand Down
28 changes: 28 additions & 0 deletions lib/flash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@flash_messages = {:error => [], :success => []}
def print_flash_messages
unless @flash_messages[:error].empty? and @flash_messages[:success].empty?
if @flash_messages[:error]
@flash_messages[:error].each do |v|
puts " ".white_on_red + " " + v
end
end
if @flash_messages[:success]
@flash_messages[:success].each do |v|
puts " ".black_on_green + " " + v
end
end
end
@flash_messages = {:error => [], :success => []}
end

def flash type, text
@flash_messages[type].push text
end

def flash_s text
flash :success, text
end

def flash_e text
flash :error, text
end

0 comments on commit e4fb5a7

Please sign in to comment.