From e4fb5a728bcd39caf229c3cb0834f1d58538049e Mon Sep 17 00:00:00 2001 From: Aleksei Kaminin Date: Wed, 11 Jan 2012 00:22:48 +0400 Subject: [PATCH] Added flash messages --- cards | 1 + commands/file.rb | 7 +++++-- dir_mode.rb | 1 + file_mode.rb | 1 + lib/flash.rb | 28 ++++++++++++++++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 lib/flash.rb diff --git a/cards b/cards index fbba52f..c712c2b 100755 --- a/cards +++ b/cards @@ -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)) diff --git a/commands/file.rb b/commands/file.rb index a37bc14..5b98878 100644 --- a/commands/file.rb +++ b/commands/file.rb @@ -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) @@ -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 @@ -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 diff --git a/dir_mode.rb b/dir_mode.rb index 45bc4c0..5344f22 100644 --- a/dir_mode.rb +++ b/dir_mode.rb @@ -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 diff --git a/file_mode.rb b/file_mode.rb index 8362a9b..f369834 100644 --- a/file_mode.rb +++ b/file_mode.rb @@ -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 diff --git a/lib/flash.rb b/lib/flash.rb new file mode 100644 index 0000000..b75597b --- /dev/null +++ b/lib/flash.rb @@ -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