Module: Cygnus
- Extended by:
- Cygnus
- Included in:
- Cygnus
- Defined in:
- lib/cygnus.rb,
lib/cygnus/textpad.rb,
lib/cygnus/version.rb
Defined Under Namespace
Classes: DefaultFileRenderer, TextPad
Constant Summary collapse
- CONFIG_FILE =
"~/.lyrainfo"
- GMARK =
CONSTANTS
'*'
- CURMARK =
'>'
- MSCROLL =
10
- SPACE =
" "
- ON_BLUE =
BLUE = “e[1;34m”
"\e[44m"
- CURSOR_COLOR =
REVERSE = “e[7m”
""
- CLEAR =
""
- GIGA_SIZE =
code related to long listing of files
1073741824.0
- MEGA_SIZE =
1048576.0
- KILO_SIZE =
1024.0
- VERSION =
"0.0.7"
Instance Method Summary collapse
- #ack ⇒ Object
-
#ask_hint(text, deflt = nil) ⇒ Object
prompt user for file shortcut and return file or nil.
-
#bindkey_ext_command ⇒ Object
bind a key to an external command wich can be then be used for files.
-
#c_refresh ⇒ Object
refresh listing after some change like option change, or toggle I think NCurses has a refresh which when called internally results in this chap getting called since both are included.
- #c_system(command) ⇒ Object
- #child_dirs ⇒ Object
-
#column_next(dir = 0) ⇒ Object
0 forward and any other back/prev.
-
#columnate(ary, sz) ⇒ Object
we have unformatted data i need to mix the functionality into columnate_with_indexing.
-
#columnate_with_indexing(ary, sz) ⇒ Object
sz - lines in one column.
- #columns_incdec(howmany) ⇒ Object
-
#command_file(prompt, *command) ⇒ Object
generic external command program prompt is the user friendly text of command such as list for ls, or extract for dtrx, page for less pauseyn is whether to pause after command as in file or ls.
- #command_menu ⇒ Object
-
#command_mode ⇒ Object
toggle command mode.
-
#config_read ⇒ Object
read dirs and files and bookmarks from file.
-
#config_write ⇒ Object
save dirs and files and bookmarks to a file.
-
#create_bookmark ⇒ Object
accept a character to save this dir as a bookmark.
- #cursor_dn ⇒ Object
-
#cursor_scroll_dn ⇒ Object
some cursor movement functions.
- #cursor_scroll_up ⇒ Object
- #cursor_up ⇒ Object
-
#date_format(t) ⇒ Object
format date for file given stat.
- #delete_file ⇒ Object
- #dirtree ⇒ Object
-
#enhance_file_list ⇒ Object
include files.
-
#enter_regex ⇒ Object
take regex from user, to run on files on screen, user can filter file names.
-
#escape ⇒ Object
clear sort order and refresh listing, used typically if you are in some view such as visited dirs or files.
- #extras ⇒ Object
- #ffind ⇒ Object
-
#file_actions(action = nil) ⇒ Object
I should be able to pass in new actions that are external commands.
- #file_matching?(file, patt) ⇒ Boolean
-
#filetype(f) ⇒ Object
- $log.debug “XXX: GOTO_LINE #$sta
-
#$cursor“.
- #filter_menu ⇒ Object
-
#format(ary) ⇒ Object
formats the data with number, mark and details.
-
#get_char ⇒ Object
I thin we need to make this like the command line one TODO.
- #get_env_paths ⇒ Object
-
#get_important_files(dir) ⇒ Object
checks various lists like visited_files and bookmarks to see if files from this dir or below are in it.
-
#get_index(key, vsz = 999) ⇒ Object
What if we want to also trap z with numbers for other purposes.
-
#get_line(text, config = {}) ⇒ Object
identical to get_string but does not show as a popup with buttons, just ENTER This is required if there are multiple inputs required and having several get_strings one after the other seems really odd due to multiple popups Unlike, get_string this does not return a nil if C-c pressed.
-
#get_shortcut(ix) ⇒ Object
Also, display ROWS * COLS so now we are not limited to 60.
-
#get_single(text, config = {}) ⇒ Object
It uses a window, so underlying text is not touched.
-
#goto_dir ⇒ Object
accept dir to goto and change to that ( can be a file too).
-
#goto_entry_starting_with(fc = nil) ⇒ Object
This actually filters, in zfm it goes to that entry since we have a cursor there.
-
#goto_line(pos) ⇒ Object
therefore calculate the correct start offset of the display also.
- #goto_parent_dir ⇒ Object
- #insert_into_list(dir, file) ⇒ Object
- #locate ⇒ Object
-
#main_menu ⇒ Object
MENU MAIN – keep consistent with zfm.
- #moveto(pos) ⇒ Object
- #newdir ⇒ Object
- #newfile ⇒ Object
- #next_page ⇒ Object
- #pause(text = " Press a key ...") ⇒ Object
- #pbold(text) ⇒ Object
- #perror(text) ⇒ Object
-
#pop_dir ⇒ Object
part copied and changed from change_dir since we don’t dir going back on top or we’ll be stuck in a cycle.
- #pos ⇒ Object
- #prev_page ⇒ Object
- #print_help ⇒ Object
-
#push_used_dirs(d = Dir.pwd) ⇒ Object
create a list of dirs in which some action has happened, for saving.
- #quit_command ⇒ Object
-
#readable_file_size(size, precision) ⇒ Object
Return the file size with a readable style.
- #recent_files ⇒ Object
-
#remove_from_list ⇒ Object
Editing of the User Dir List.
-
#return_next_match(binding, *args) ⇒ Object
generic method to take cursor to next position for a given condition.
- #revert_dir_pos ⇒ Object
-
#run_command(f) ⇒ Object
run command on given file/s Accepts command from user After putting readline in place of gets, pressing a C-c has a delayed effect.
- #save_dir_pos ⇒ Object
-
#screen_settings ⇒ Object
check screen size and accordingly adjust some variables.
-
#select_all ⇒ Object
select all files.
- #select_bookmarks ⇒ Object
- #select_current ⇒ Object
-
#select_hint(view, ch) ⇒ Object
select file based on key pressed.
- #select_used_dirs ⇒ Object
-
#select_visited_files ⇒ Object
show_list.
-
#selection_mode_toggle ⇒ Object
toggle mode to selection or not In selection, pressed hotkey selects a file without opening, one can keep selecting (or deselecting).
- #show_marks ⇒ Object
- #sort_menu ⇒ Object
- #subcommand ⇒ Object
-
#TODOpost_cd ⇒ Object
TODO.
- #toggle_menu ⇒ Object
-
#toggle_select(f) ⇒ Object
toggle selection state of file.
-
#tree ⇒ Object
structure than files.
-
#unselect_all ⇒ Object
unselect all files.
- #views ⇒ Object
- #viminfo ⇒ Object
- #visual_block_clear ⇒ Object
- #visual_mode_toggle ⇒ Object
- #z_interface ⇒ Object
Instance Method Details
#ack ⇒ Object
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 |
# File 'lib/cygnus.rb', line 1200 def ack pattern = get_line "Enter a pattern to search (ack): " return if pattern.nil? || pattern == "" $title = "Files found using 'ack' #{pattern}" #system("ack #{pattern}") #pause files = `ack -l #{pattern}`.split("\n") if files.size == 0 perror "No files found." else $files = files show_list end end |
#ask_hint(text, deflt = nil) ⇒ Object
prompt user for file shortcut and return file or nil
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
# File 'lib/cygnus.rb', line 1007 def ask_hint text, deflt=nil f = nil #ch = get_char ch = get_single text if ch == "ENTER" return deflt end ix = get_index(ch, $viewport.size) f = $viewport[ix] if ix return f end |
#bindkey_ext_command ⇒ Object
bind a key to an external command wich can be then be used for files
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 |
# File 'lib/cygnus.rb', line 1159 def bindkey_ext_command #print #pbold "Bind a capital letter to an external command" ch = get_single "Enter a capital letter to bind: " #ch = get_char return if ch == "Q" if ch =~ /^[A-Z]$/ print "Enter an external command to bind to #{ch}: " com = gets().chomp if com != "" print "Enter prompt for command (blank if same as command): " pro = gets().chomp pro = com if pro == "" end print "Pause after output [y/n]: " yn = get_char $bindings[ch] = "command_file #{pro} #{yn} #{com}" end end |
#c_refresh ⇒ Object
refresh listing after some change like option change, or toggle I think NCurses has a refresh which when called internally results in this chap getting called since both are included. or maybe App or somehting has a refresh
358 359 360 361 362 363 364 |
# File 'lib/cygnus.rb', line 358 def c_refresh $filterstr ||= "M" #$files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}#{$filterstr})'`.split("\n") $patt=nil $title = nil display_dir end |
#c_system(command) ⇒ Object
333 334 335 336 337 338 339 340 341 |
# File 'lib/cygnus.rb', line 333 def c_system command w = @window || @form.window w.hide Ncurses.endwin ret = system command Ncurses.refresh w.show return ret end |
#child_dirs ⇒ Object
878 879 880 881 |
# File 'lib/cygnus.rb', line 878 def child_dirs $title = "Child directories" $files = `zsh -c 'print -rl -- *(/#{$sorto}#{$hidden}M)'`.split("\n") end |
#column_next(dir = 0) ⇒ Object
0 forward and any other back/prev
1034 1035 1036 1037 1038 1039 1040 1041 1042 |
# File 'lib/cygnus.rb', line 1034 def column_next dir=0 if dir == 0 $stact += $grows $stact = 0 if $stact >= $viewport.size else $stact -= $grows $stact = 0 if $stact < 0 end end |
#columnate(ary, sz) ⇒ Object
we have unformatted data i need to mix the functionality into columnate_with_indexing
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/cygnus.rb', line 194 def columnate ary, sz buff=Array.new return buff if ary.nil? || ary.size == 0 # ix refers to the index in the complete file list, wherease we only show 60 at a time ix=0 while true ## ctr refers to the index in the column ctr=0 while ctr < sz f = ary[ix] # deleted truncate and pad part since we expect cols to be sized same if buff[ctr] buff[ctr] += f else buff[ctr] = f end ctr+=1 ix+=1 break if ix >= ary.size end break if ix >= ary.size end return buff end |
#columnate_with_indexing(ary, sz) ⇒ Object
sz - lines in one column
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/cygnus.rb', line 95 def columnate_with_indexing ary, sz buff=Array.new $log.warn "columnate_with_indexing got nil list " unless ary return buff if ary.nil? || ary.size == 0 # determine width based on number of files to show # if less than sz then 1 col and full width # wid = 30 ars = ary.size ars = [$pagesize, ary.size].min # 2 maybe for borders also d = 0 if ars <= sz wid = $gcols - d else tmp = (ars * 1.000/ sz).ceil wid = $gcols / tmp - d end # ix refers to the index in the complete file list, wherease we only show 60 at a time ix=0 while true ## ctr refers to the index in the column ctr=0 while ctr < sz cur=SPACE cur = CURMARK if ix + $sta == $cursor f = ary[ix] if $long_listing begin # one of zsh's flags adds not just / but @ * and a space, so the a FNF error comes unless File.exist? f last = f[-1] if last == " " || last == "@" || last == '*' stat = File.stat(f.chop) end else stat = File.stat(f) end f = "%10s %s %s" % [readable_file_size(stat.size,1), date_format(stat.mtime), f] rescue Exception => e f = "%10s %s %s" % ["?", "??????????", f] end end # be careful of modifying f or original array gets modified XXX k = get_shortcut ix isdir = f[-1] == "/" fsz = f.size + k.to_s.size + 0 fsz = f.size + 1 if fsz > wid # truncated since longer f = f[0, wid-2]+"$ " ## we do the coloring after trunc so ANSI escpe seq does not get get #if ix + $sta == $cursor #f = "#{CURSOR_COLOR}#{f}#{CLEAR}" #end else ## we do the coloring before padding so the entire line does not get padded, only file name #if ix + $sta == $cursor #f = "#{CURSOR_COLOR}#{f}#{CLEAR}" #end f = f.ljust(wid) # pad with spaces #f << " " * (wid-fsz) #f = f + " " * (wid-fsz) end # now we add the shortcut with the coloring (we need to adjust the space of the shortcut) # colr = "white" colr = "blue, bold" if isdir # this directly modified the damned index resulting in searches failing #k << " " if k.length == 1 k = k + " " if k.length == 1 f = "#{cur}#[fg=yellow, bold]#{k}#[end] #[fg=#{colr}]#{f}#[end]" if buff[ctr] buff[ctr] += f else buff[ctr] = f end ctr+=1 ix+=1 break if ix >= ary.size end break if ix >= ary.size end return buff end |
#columns_incdec(howmany) ⇒ Object
1151 1152 1153 1154 1155 1156 |
# File 'lib/cygnus.rb', line 1151 def columns_incdec howmany $gviscols += howmany.to_i $gviscols = 1 if $gviscols < 1 $gviscols = 6 if $gviscols > 6 $pagesize = $grows * $gviscols end |
#command_file(prompt, *command) ⇒ Object
generic external command program
prompt is the user friendly text of command such as list for ls, or extract for dtrx, page for less
pauseyn is whether to pause after command as in file or ls
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 |
# File 'lib/cygnus.rb', line 983 def command_file prompt, *command pauseyn = command.shift command = command.join " " #print "[#{prompt}] Choose a file [#{$view[$cursor]}]: " t = "[#{prompt}] Choose a file [#{$view[$cursor]}]: " file = ask_hint t, $view[$cursor] #print "#{prompt} :: Enter file shortcut: " #file = ask_hint perror "Command Cancelled" unless file return unless file file = File.(file) if File.exists? file file = Shellwords.escape(file) pbold "#{command} #{file} (press a key)" c_system "#{command} #{file}" pause if pauseyn == "y" c_refresh else perror "File #{file} not found" end end |
#command_menu ⇒ Object
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
# File 'lib/cygnus.rb', line 596 def ## # since these involve full paths, we need more space, like only one column # ## in these cases, getting back to the earlier dir, back to earlier listing # since we've basically overlaid the old listing # # should be able to sort THIS listing and not rerun command. But for that I'd need to use # xargs ls -t etc rather than the zsh sort order. But we can run a filter using |. # h = { :t => :today, :D => :default_command , :R => :remove_from_list} if $editor_mode h[:e] = :pager_mode else h[:e] = :editor_mode end ch, = "Command Menu", h case when :pager_mode $editor_mode = false $default_command = ENV['MANPAGER'] || ENV['PAGER'] when :editor_mode $editor_mode = true $default_command = nil when :ffind ffind when :locate locate when :today $files = `zsh -c 'print -rl -- *(#{$hidden}Mm0)'`.split("\n") $title = "Today's files" when :default_command print "Selecting a file usually invokes $EDITOR, what command do you want to use repeatedly on selected files: " $default_command = gets().chomp if $default_command != "" print "Second part of command (maybe blank): " $default_command2 = gets().chomp else print "Cleared default command, will default to $EDITOR" $default_command2 = nil $default_command = nil end end end |
#command_mode ⇒ Object
toggle command mode
421 422 423 424 425 426 427 |
# File 'lib/cygnus.rb', line 421 def command_mode if $mode == 'COM' $mode = nil return end $mode = 'COM' end |
#config_read ⇒ Object
read dirs and files and bookmarks from file
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
# File 'lib/cygnus.rb', line 749 def config_read #f = File.expand_path("~/.zfminfo") f = File.(CONFIG_FILE) if File.readable? f load f # maybe we should check for these existing else crash will happen. $used_dirs.push(*(DIRS.split ":")) $used_dirs.concat get_env_paths $visited_files.push(*(FILES.split ":")) #$bookmarks.push(*bookmarks) if bookmarks chars = ('A'..'Z').to_a chars.concat( ('0'..'9').to_a ) chars.each do |ch| if Kernel.const_defined? "BM_#{ch}" $bookmarks[ch] = Kernel.const_get "BM_#{ch}" end end end end |
#config_write ⇒ Object
save dirs and files and bookmarks to a file
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/cygnus.rb', line 782 def config_write # Putting it in a format that zfm can also read and write f1 = File.("~/.cygnusinfo") #f1 = File.expand_path(CONFIG_FILE) d = $used_dirs.join ":" f = $visited_files.join ":" File.open(f1, 'w+') do |f2| # use "\n" for two lines of text f2.puts "DIRS=\"#{d}\"" f2.puts "FILES=\"#{f}\"" $bookmarks.each_pair { |k, val| f2.puts "BM_#{k}=\"#{val}\"" #f2.puts "BOOKMARKS[\"#{k}\"]=\"#{val}\"" } end $writing = $modified = false end |
#create_bookmark ⇒ Object
accept a character to save this dir as a bookmark
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 |
# File 'lib/cygnus.rb', line 801 def create_bookmark ch = get_single "Enter A to Z or 0-9 for bookmark: " #ch = get_char if ch =~ /^[0-9A-Z]$/ #$bookmarks[ch] = "#{Dir.pwd}:#{$cursor}" # # The significance of putting a : and not a / is that with a # : the dir will be opened with cursor on same object it was on, and not # go into the dir. e.g, If bookmark is created with cursor on a dir, we don't want # it to go into the dir. $bookmarks[ch] = "#{Dir.pwd}:#{$view[$cursor]}" $modified = true else perror "Bookmark must be upper-case character or number." end end |
#cursor_dn ⇒ Object
1257 1258 1259 |
# File 'lib/cygnus.rb', line 1257 def cursor_dn moveto(pos() + 1) end |
#cursor_scroll_dn ⇒ Object
some cursor movement functions
1251 1252 1253 |
# File 'lib/cygnus.rb', line 1251 def cursor_scroll_dn moveto(pos() + MSCROLL) end |
#cursor_scroll_up ⇒ Object
1254 1255 1256 |
# File 'lib/cygnus.rb', line 1254 def cursor_scroll_up moveto(pos() - MSCROLL) end |
#cursor_up ⇒ Object
1260 1261 1262 |
# File 'lib/cygnus.rb', line 1260 def cursor_up moveto(pos() - 1) end |
#date_format(t) ⇒ Object
format date for file given stat
86 87 88 |
# File 'lib/cygnus.rb', line 86 def date_format t t.strftime "%Y/%m/%d" end |
#delete_file ⇒ Object
975 976 977 |
# File 'lib/cygnus.rb', line 975 def delete_file file_actions :delete end |
#dirtree ⇒ Object
882 883 884 885 |
# File 'lib/cygnus.rb', line 882 def dirtree $title = "Child directories" $files = `zsh -c 'print -rl -- **/*(/#{$sorto}#{$hidden}M)'`.split("\n") end |
#enhance_file_list ⇒ Object
include files.
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 |
# File 'lib/cygnus.rb', line 1433 def enhance_file_list return unless $enhanced_mode # if only one entry and its a dir # get its children and maybe the recent mod files a few # zsh gives errors which stick on stdscr and don't get off! # Rather than using N I'll try to convert to ruby, but then we lose # similarity to cetus and its tough to redo all the sorting stuff. if $files.size == 1 # its a dir, let give the next level at least if $files.first[-1] == "/" d = $files.first #f = `zsh -c 'print -rl -- #{d}*(omM)'`.split("\n") f = get_file_list d if f && f.size > 0 $files.concat f $files.concat get_important_files(d) return end else # just a file, not dirs here return end end # # check if a ruby project dir, although it could be a backup file too, # if so , expand lib and maby bin, put a couple recent files # if $files.index("Gemfile") || $files.grep(/\.gemspec/).size > 0 # usually the lib dir has only one file and one dir flg = false $files.concat get_important_files(Dir.pwd) if $files.index("lib/") f = `zsh -c 'print -rl -- lib/*(om[1,5]MN)'`.split("\n") if f && f.size() > 0 insert_into_list("lib/", f) flg = true end dd = File.basename(Dir.pwd) if f.index("lib/#{dd}/") f = `zsh -c 'print -rl -- lib/#{dd}/*(om[1,5]MN)'`.split("\n") if f && f.size() > 0 insert_into_list("lib/#{dd}/", f) flg = true end end end if $files.index("bin/") f = `zsh -c 'print -rl -- bin/*(om[1,5]MN)'`.split("\n") insert_into_list("bin/", f) if f && f.size() > 0 flg = true end return if flg # lib has a dir in it with the gem name end return if $files.size > 15 ## first check accessed else modified will change accessed moda = `zsh -c 'print -rn -- *(/oa[1]MN)'` if moda && moda != "" modf = `zsh -c 'print -rn -- #{moda}*(oa[1]MN)'` if modf && modf != "" insert_into_list moda, modf end modm = `zsh -c 'print -rn -- #{moda}*(om[1]MN)'` if modm && modm != "" && modm != modf insert_into_list moda, modm end end ## get last modified dir modm = `zsh -c 'print -rn -- *(/om[1]MN)'` if modm != moda modmf = `zsh -c 'print -rn -- #{modm}*(oa[1]MN)'` insert_into_list modm, modmf modmf1 = `zsh -c 'print -rn -- #{modm}*(om[1]MN)'` insert_into_list(modm, modmf1) if modmf1 != modmf else # if both are same then our options get reduced so we need to get something more # If you access the latest mod dir, then come back you get only one, since mod and accessed # are the same dir, so we need to find the second modified dir end end |
#enter_regex ⇒ Object
take regex from user, to run on files on screen, user can filter file names
446 447 448 449 450 451 452 |
# File 'lib/cygnus.rb', line 446 def enter_regex patt = get_line "Enter (regex) pattern: " #$patt = gets().chomp #$patt = Readline::readline('>', true) $patt = patt return patt end |
#escape ⇒ Object
clear sort order and refresh listing, used typically if you are in some view
such as visited dirs or files
345 346 347 348 349 350 351 352 353 |
# File 'lib/cygnus.rb', line 345 def escape $sorto = nil $sorto = $default_sort_order $viewctr = 0 $title = nil $filterstr = "M" visual_block_clear c_refresh end |
#extras ⇒ Object
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 |
# File 'lib/cygnus.rb', line 640 def extras h = { "1" => :one_column, "2" => :multi_column, :c => :columns, :r => :config_read , :w => :config_write} ch, = "Extras Menu", h case when :one_column $pagesize = $grows when :multi_column #$pagesize = 60 $pagesize = $grows * $gviscols when :columns ch = get_single "How many columns to show: 1-6 [current #{$gviscols}]? " #ch = get_char ch = ch.to_i if ch > 0 && ch < 7 $gviscols = ch.to_i $pagesize = $grows * $gviscols end end end |
#ffind ⇒ Object
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 |
# File 'lib/cygnus.rb', line 1214 def ffind pattern = get_line "Enter a file name pattern to find: " return if pattern.nil? || pattern == "" $title = "Files found using 'find' #{pattern}" files = `find . -name '#{pattern}'`.split("\n") if files.size == 0 perror "No files found." else $files = files show_list end end |
#file_actions(action = nil) ⇒ Object
I should be able to pass in new actions that are external commands
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 |
# File 'lib/cygnus.rb', line 1045 def file_actions action=nil h = { :d => :delete, :m => :move, :r => :rename, :v => ENV["EDITOR"] || :vim, :c => :copy, :C => :chdir, :l => :less, :s => :most , :f => :file , :o => :open, :x => :dtrx, :z => :zip } #acttext = h[action.to_sym] || action acttext = action || "" file = nil sct = $selected_files.size if sct > 0 text = "#{sct} files" file = $selected_files else #print "[#{acttext}] Choose a file [#{$view[$cursor]}]: " t = "[#{acttext}] Choose a file [#{$view[$cursor]}]: " file = ask_hint t, $view[$cursor] return unless file text = file end case file when Array # escape the contents and create a string files = Shellwords.join(file) when String files = Shellwords.escape(file) end ch = nil if action = action else ch, = "File Menu for #{text}", h = :quit if ch == "q" end return unless case .to_sym when :quit when :delete ch = get_single "rmtrash #{files} ?[yn]: " #print "rmtrash #{files} ?[yn]: " #ch = get_char return if ch != "y" c_system "rmtrash #{files}" c_refresh when :move #print "move #{text} to : " #target = gets().chomp #target = Readline::readline('>', true) target = get_line "move #{text} to : " text=File.(text) return if target.nil? || target == "" if File.directory? target FileUtils.mv text, target c_refresh else perror "Target not a dir" end when :copy target = get_line "copy #{text} to : " #target = Readline::readline('>', true) return if target.nil? || target == "" text=File.(text) target = File.basename(text) if target == "." if File.exists? target perror "Target (#{target}) exists" else FileUtils.cp text, target c_refresh end when :chdir change_dir File.dirname(text) when :zip target = get_line "Archive name: " #target = gets().chomp #target = Readline::readline('>', true) return if target.nil? || target == "" # don't want a blank space or something screwing up if target && target.size > 3 if File.exists? target perror "Target (#{target}) exists" else c_system "tar zcvf #{target} #{files}" c_refresh end end when :rename when :most, :less, :vim, ENV['EDITOR'] c_system "#{} #{files}" else return unless $log.debug "XXX: menu_text #{.to_sym}" get_single "#{} #{files}" #pause #print c_system "#{} #{files}" pause c_refresh end # remove non-existent files from select list due to move or delete or rename or whatever if sct > 0 $selected_files.reject! {|x| x = File.(x); !File.exists?(x) } end end |
#file_matching?(file, patt) ⇒ Boolean
1302 1303 1304 |
# File 'lib/cygnus.rb', line 1302 def file_matching? file, patt file =~ /#{patt}/ end |
#filetype(f) ⇒ Object
- $log.debug “XXX: GOTO_LINE #$sta
-
#$cursor“
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 |
# File 'lib/cygnus.rb', line 1333 def filetype f return nil unless f f = Shellwords.escape(f) s = `file #{f}` if s.index "text" return :text elsif s.index(/[Zz]ip/) return :zip elsif s.index("archive") return :zip elsif s.index "image" return :image elsif s.index "data" return :text else return :directory if File.directory? f end return :unknown end |
#filter_menu ⇒ Object
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 |
# File 'lib/cygnus.rb', line 659 def h = { :d => :dirs, :f => :files, :e => :emptydirs , "0" => :emptyfiles} ch, = "Filter Menu", h files = nil case when :dirs $filterstr = "/M" files = `zsh -c 'print -rl -- *(#{$sorto}/M)'`.split("\n") $title = "Filter: directories only" when :files $filterstr = "." files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}.)'`.split("\n") $title = "Filter: files only" when :emptydirs $filterstr = "/D^F" files = `zsh -c 'print -rl -- *(#{$sorto}/D^F)'`.split("\n") $title = "Filter: empty directories" when :emptyfiles $filterstr = ".L0" files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}.L0)'`.split("\n") $title = "Filter: empty files" end if files $files = files show_list $stact = 0 end end |
#format(ary) ⇒ Object
formats the data with number, mark and details
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/cygnus.rb', line 223 def format ary alert "deprecated, can be removed if not called" #buff = Array.new buff = Array.new(ary.size) return buff if ary.nil? || ary.size == 0 # determine width based on number of files to show # if less than sz then 1 col and full width # # ix refers to the index in the complete file list, wherease we only show 60 at a time ix=0 ctr=0 ary.each do |f| ## ctr refers to the index in the column ind = get_shortcut(ix) mark=SPACE cur=SPACE cur = CURMARK if ix + $sta == $cursor mark=GMARK if $selected_files.index(ary[ix]) if $long_listing begin unless File.exist? f last = f[-1] if last == " " || last == "@" || last == '*' stat = File.stat(f.chop) end else stat = File.stat(f) end f = "%10s %s %s" % [readable_file_size(stat.size,1), date_format(stat.mtime), f] rescue Exception => e f = "%10s %s %s" % ["?", "??????????", f] end end s = "#{ind}#{mark}#{cur}#{f}" # I cannot color the current line since format does the chopping # so not only does the next lines alignment get skeweed, but also if the line is truncated # then the color overflows. #if ix + $sta == $cursor #s = "#{RED}#{s}#{CLEAR}" #end buff[ctr] = s ctr+=1 ix+=1 end return buff end |
#get_char ⇒ Object
I thin we need to make this like the command line one TODO
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 |
# File 'lib/cygnus.rb', line 910 def get_char c = @window.getchar case c when 13,10 return "ENTER" when 32 return "SPACE" when 127 return "BACKSPACE" when 27 return "ESCAPE" end keycode_tos c # if c > 32 && c < 127 #return c.chr #end ## use keycode_tos from Utils. end |
#get_env_paths ⇒ Object
768 769 770 771 772 773 774 775 776 777 778 779 |
# File 'lib/cygnus.rb', line 768 def get_env_paths files = [] %w{ GEM_HOME PYTHONHOME}.each do |p| d = ENV[p] files.push d if d end %w{ RUBYLIB RUBYPATH GEM_PATH PYTHONPATH }.each do |p| d = ENV[p] files.concat d.split(":") if d end return files end |
#get_important_files(dir) ⇒ Object
checks various lists like visited_files and bookmarks to see if files from this dir or below are in it. More to be used in a dir with few files.
1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 |
# File 'lib/cygnus.rb', line 1529 def get_important_files dir list = [] l = dir.size + 1 s = nil ($visited_files + $bookmarks.values).each do |e| if e.index(dir) == 0 #list << e[l..-1] s = e[l..-1] next unless s if s.index ":" s = s[0, s.index(":")] + "/" end # only insert if the file is in a deeper dir, otherwise we'll be duplicating files from this folder list << s if s.index "/" end end # bookmarks have : which needs to be removed #list1 = $bookmarks.values.select do |e| #e.index(dir) == 0 #end #list.concat list1 return list end |
#get_index(key, vsz = 999) ⇒ Object
What if we want to also trap z with numbers for other purposes
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 |
# File 'lib/cygnus.rb', line 958 def get_index key, vsz=999 i = $IDX.index(key) return i+$stact if i #sz = $IDX.size zch = nil if vsz > 25 if key == "z" || key == "Z" #print key zch = get_char #print zch i = $IDX.index("#{key}#{zch}") return i+$stact if i end end return nil end |
#get_line(text, config = {}) ⇒ Object
identical to get_string but does not show as a popup with buttons, just ENTER This is required if there are multiple inputs required and having several get_strings one after the other seems really odd due to multiple popups Unlike, get_string this does not return a nil if C-c pressed. Either returns a string if ENTER pressed or a blank if C-c or Double Escape. So only blank to be checked
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 |
# File 'lib/cygnus.rb', line 1578 def get_line text, config={} begin w = one_line_window form = RubyCurses::Form.new w f = Field.new form, :label => text, :row => 0, :col => 1 form.repaint w.wrefresh while((ch = w.getchar()) != FFI::NCurses::KEY_F10 ) break if ch == 13 if ch == 3 || ch == 27 || ch == 2727 return "" end begin form.handle_key(ch) w.wrefresh rescue => err $log.debug( err) if err $log.debug(err.backtrace.join("\n")) if err textdialog ["Error in Messagebox: #{err} ", *err.backtrace], :title => "Exception" w.refresh # otherwise the window keeps showing (new FFI-ncurses issue) $error_message.value = "" ensure end end # while loop ensure w.destroy w = nil end return f.text end |
#get_shortcut(ix) ⇒ Object
Also, display ROWS * COLS so now we are not limited to 60.
947 948 949 950 951 952 953 |
# File 'lib/cygnus.rb', line 947 def get_shortcut ix return "<" if ix < $stact ix -= $stact i = $IDX[ix] return i if i return "->" end |
#get_single(text, config = {}) ⇒ Object
It uses a window, so underlying text is not touched.
1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 |
# File 'lib/cygnus.rb', line 1557 def get_single text, config={} w = one_line_window x = y = 0 color = config[:color_pair] || $datacolor color=Ncurses.COLOR_PAIR(color); w.attron(color); w.mvprintw(x, y, "%s" % text); w.attroff(color); w.wrefresh Ncurses::Panel.update_panels chr = get_char w.destroy w = nil return chr end |
#goto_dir ⇒ Object
accept dir to goto and change to that ( can be a file too)
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/cygnus.rb', line 378 def goto_dir begin path = get_line "Enter path: " return if path.nil? || path == "" rescue Exception => ex perror "Cancelled cd, press a key" return end f = File.(path) unless File.directory? f ## check for env variable tmp = ENV[path] if tmp.nil? || !File.directory?( tmp ) ## check for dir in home tmp = File.("~/#{path}") if File.directory? tmp f = tmp end else f = tmp end end open_file f end |
#goto_entry_starting_with(fc = nil) ⇒ Object
This actually filters, in zfm it goes to that entry since we have a cursor there
433 434 435 436 437 438 439 440 441 442 |
# File 'lib/cygnus.rb', line 433 def goto_entry_starting_with fc=nil unless fc fc = get_single "Entries starting with: " #fc = get_char end return if fc.size != 1 ## this is wrong and duplicates the functionality of / # It shoud go to cursor of item starting with fc $patt = "^#{fc}" end |
#goto_line(pos) ⇒ Object
therefore calculate the correct start offset of the display also.
1325 1326 1327 1328 1329 1330 1331 1332 |
# File 'lib/cygnus.rb', line 1325 def goto_line pos pages = ((pos * 1.00)/$pagesize).ceil pages -= 1 #$sta = pages * $pagesize + 1 $sta = pages * $pagesize + 0 $cursor = pos #$log.debug "XXX: GOTO_LINE #{$sta} :: #{$cursor}" end |
#goto_parent_dir ⇒ Object
428 429 430 |
# File 'lib/cygnus.rb', line 428 def goto_parent_dir change_dir ".." end |
#insert_into_list(dir, file) ⇒ Object
1517 1518 1519 1520 1521 1522 1523 1524 |
# File 'lib/cygnus.rb', line 1517 def insert_into_list dir, file ## earlier we were inserting these files at helpful points (before the dirs), but they are touch to find. # I think it;s better to put at end #ix = $files.index(dir) #raise "something wrong can find #{dir}." unless ix #$files.insert ix, *file $files.push *file end |
#locate ⇒ Object
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
# File 'lib/cygnus.rb', line 1226 def locate pattern = get_line "Enter a file name pattern to locate: " return if pattern.nil? || pattern == "" $title = "Files found using 'locate' #{pattern}" files = `locate #{pattern}`.split("\n") files.reject! {|x| x = File.(x); !File.exists?(x) } if files.size == 0 perror "No files found." else $files = files show_list end end |
#main_menu ⇒ Object
MENU MAIN – keep consistent with zfm
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/cygnus.rb', line 501 def h = { :a => :ack, "/" => :ffind, :l => :locate, :v => :viminfo, :z => :z_interface, :d => :child_dirs, :r => :recent_files, :t => :dirtree, "4" => :tree, :s => :sort_menu, :F => :filter_menu, :c => :command_menu , :B => :bindkey_ext_command, :M => :newdir, "%" => :newfile, :x => :extras } "Main Menu", h end |
#moveto(pos) ⇒ Object
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 |
# File 'lib/cygnus.rb', line 1267 def moveto pos orig = $cursor $cursor = pos $cursor = [$cursor, $view.size - 1].min $cursor = [$cursor, 0].max star = [orig, $cursor].min fin = [orig, $cursor].max if $visual_mode # PWD has to be there in selction if $selected_files.index $view[$cursor] # this depends on the direction $selected_files = $selected_files - $view[star..fin] ## current row remains in selection always. $selected_files.push $view[$cursor] else $selected_files.concat $view[star..fin] end end end |
#newdir ⇒ Object
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 |
# File 'lib/cygnus.rb', line 1368 def newdir #print #print "Enter directory name: " #str = Readline::readline('>', true) str = get_line "Enter directory name: " return if str.nil? || str == "" if File.exists? str perror "#{str} exists." return end begin FileUtils.mkdir str $used_dirs.insert(0, str) if File.exists?(str) c_refresh rescue Exception => ex perror "Error in newdir: #{ex}" end end |
#newfile ⇒ Object
1386 1387 1388 1389 1390 1391 1392 1393 1394 |
# File 'lib/cygnus.rb', line 1386 def newfile #print str = get_line "Enter file name: " #str = Readline::readline('>', true) return if str.nil? || str == "" c_system "$EDITOR #{str}" $visited_files.insert(0, str) if File.exists?(str) c_refresh end |
#next_page ⇒ Object
453 454 455 456 457 |
# File 'lib/cygnus.rb', line 453 def next_page # FIXME cursor position, take logic from zfm page calc $sta += $pagesize $cursor = $sta if $cursor < $sta end |
#pause(text = " Press a key ...") ⇒ Object
939 940 941 942 |
# File 'lib/cygnus.rb', line 939 def pause text=" Press a key ..." get_single text #get_char end |
#pbold(text) ⇒ Object
929 930 931 932 |
# File 'lib/cygnus.rb', line 929 def pbold text #puts "#{BOLD}#{text}#{BOLD_OFF}" get_single text, :color_pair => $reversecolor end |
#perror(text) ⇒ Object
933 934 935 936 937 938 |
# File 'lib/cygnus.rb', line 933 def perror text ##puts "#{RED}#{text}#{CLEAR}" #get_char #alert text get_single text + " Press a key...", :color_pair => $errorcolor end |
#pop_dir ⇒ Object
part copied and changed from change_dir since we don’t dir going back on top
or we'll be stuck in a cycle
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
# File 'lib/cygnus.rb', line 714 def pop_dir # the first time we pop, we need to put the current on stack if !$visited_dirs.index(Dir.pwd) $visited_dirs.push Dir.pwd end ## XXX make sure thre is something to pop d = $visited_dirs.delete_at 0 ## XXX make sure the dir exists, cuold have been deleted. can be an error or crash otherwise $visited_dirs.push d Dir.chdir d display_dir return # old stuff with zsh $filterstr ||= "M" $files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}#{$filterstr})'`.split("\n") post_cd end |
#pos ⇒ Object
1263 1264 1265 |
# File 'lib/cygnus.rb', line 1263 def pos $cursor end |
#prev_page ⇒ Object
458 459 460 461 462 |
# File 'lib/cygnus.rb', line 458 def prev_page # FIXME cursor position, take logic from zfm page calc $sta -= $pagesize $cursor = $sta end |
#print_help ⇒ Object
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/cygnus.rb', line 480 def print_help h = @bindings row = 1 list = [] longestval = h.values.max_by(&:length) llen = longestval.length # they must all be of same size so i can easily columnate h.each_pair { |k, v| list << " #[fg=yellow, bold]#{k.ljust(6)}#[/end] #[fg=green]#{v.ljust(llen)}#[/end]" } lines = FFI::NCurses.LINES - row list = columnate list, lines - 2 config = {} config[:row] = row config[:col] = 1 config[:title] = "Key Bindings" #config[:width] = [longestval.length + 5, FFI::NCurses.COLS - 5].min config[:width] = FFI::NCurses.COLS - config[:col] config[:height] = lines ch = padpopup list, config return unless ch end |
#push_used_dirs(d = Dir.pwd) ⇒ Object
create a list of dirs in which some action has happened, for saving
906 907 908 |
# File 'lib/cygnus.rb', line 906 def push_used_dirs d=Dir.pwd $used_dirs.index(d) || $used_dirs.push(d) end |
#quit_command ⇒ Object
853 854 855 856 857 858 859 860 861 862 863 864 865 |
# File 'lib/cygnus.rb', line 853 def quit_command if $modified s = "" s << "Press w to save bookmarks before quitting. " if $modified s << "Press another q to quit " ch = get_single s #ch = get_char else $quitting = true end $quitting = true if ch == "q" $quitting = $writing = true if ch == "w" end |
#readable_file_size(size, precision) ⇒ Object
Return the file size with a readable style.
76 77 78 79 80 81 82 83 84 |
# File 'lib/cygnus.rb', line 76 def readable_file_size(size, precision) case #when size == 1 : "1 B" when size < KILO_SIZE then "%d B" % size when size < MEGA_SIZE then "%.#{precision}f K" % (size / KILO_SIZE) when size < GIGA_SIZE then "%.#{precision}f M" % (size / MEGA_SIZE) else "%.#{precision}f G" % (size / GIGA_SIZE) end end |
#recent_files ⇒ Object
894 895 896 897 898 |
# File 'lib/cygnus.rb', line 894 def recent_files # print -rl -- **/*(Dom[1,10]) $title = "Recent files" $files = `zsh -c 'print -rl -- **/*(Dom[1,15])'`.split("\n") end |
#remove_from_list ⇒ Object
Editing of the User Dir List. remove current entry from used dirs list, since we may not want some entries being there
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 |
# File 'lib/cygnus.rb', line 1400 def remove_from_list if $selected_files.size > 0 sz = $selected_files.size ch = get_single "Remove #{sz} files from used list (y)?: " #ch = get_char return if ch != "y" $used_dirs = $used_dirs - $selected_files $visited_files = $visited_files - $selected_files unselect_all $modified = true return end #print ## what if selected some rows file = $view[$cursor] ch = get_single "Remove #{file} from used list (y)?: " #ch = get_char return if ch != "y" file = File.(file) if File.directory? file $used_dirs.delete(file) else $visited_files.delete(file) end c_refresh $modified = true end |
#return_next_match(binding, *args) ⇒ Object
generic method to take cursor to next position for a given condition
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 |
# File 'lib/cygnus.rb', line 1307 def return_next_match binding, *args first = nil ix = 0 $view.each_with_index do |elem,ii| if binding.call(elem, *args) first ||= ii if ii > $cursor ix = ii break end end end return first if ix == 0 return ix end |
#revert_dir_pos ⇒ Object
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 |
# File 'lib/cygnus.rb', line 1357 def revert_dir_pos $sta = 0 $cursor = 0 a = $dir_position[Dir.pwd] if a $sta = a.first $cursor = a[1] raise "sta is nil for #{Dir.pwd} : #{$dir_position[Dir.pwd]}" unless $sta raise "cursor is nil" unless $cursor end end |
#run_command(f) ⇒ Object
run command on given file/s
Accepts command from user
After putting readline in place of gets, pressing a C-c has a delayed effect. It goes intot
exception bloack after executing other commands and still does not do the return !
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/cygnus.rb', line 308 def run_command f files=nil case f when Array # escape the contents and create a string files = Shellwords.join(f) when String files = Shellwords.escape(f) end begin # TODO put all this get_line stuff into field history command = get_line "Run a command on #{files}: " return if command.size == 0 command2 = get_line "Second part of command: " # FIXME we may need to go into cooked mode and all that for this # cat and most mess with the output using system c_system "#{command} #{files} #{command2}" rescue Exception => ex perror "Canceled command, (#{ex}) press a key" return end c_refresh push_used_dirs Dir.pwd end |
#save_dir_pos ⇒ Object
1353 1354 1355 1356 |
# File 'lib/cygnus.rb', line 1353 def save_dir_pos return if $sta == 0 && $cursor == 0 $dir_position[Dir.pwd] = [$sta, $cursor] end |
#screen_settings ⇒ Object
check screen size and accordingly adjust some variables
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 |
# File 'lib/cygnus.rb', line 1022 def screen_settings # TODO these need to become part of our new full_indexer class, not hang about separately. $glines=%x(tput lines).to_i $gcols=%x(tput cols).to_i # this depends now on textpad size not screen size TODO FIXME $grows = $glines - 1 $pagesize = 60 #$gviscols = 3 $pagesize = $grows * $gviscols end |
#select_all ⇒ Object
select all files
373 374 375 |
# File 'lib/cygnus.rb', line 373 def select_all $selected_files = $view.dup end |
#select_bookmarks ⇒ Object
699 700 701 702 703 704 705 706 707 708 709 710 |
# File 'lib/cygnus.rb', line 699 def select_bookmarks $title = "Bookmarks" $files = $bookmarks.values.collect do |x| if x.include? ":" ix = x.index ":" x[0,ix] else x end end #show_list files end |
#select_current ⇒ Object
899 900 901 902 903 |
# File 'lib/cygnus.rb', line 899 def select_current ## vp is local there, so i can do $vp[0] #open_file $view[$sta] if $view[$sta] open_file $view[$cursor] if $view[$cursor] end |
#select_hint(view, ch) ⇒ Object
select file based on key pressed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/cygnus.rb', line 275 def select_hint view, ch # a to y is direct # if z or Z take a key IF there are those many # ix = get_index(ch, view.size) if ix f = view[ix] return unless f $cursor = $sta + ix if $mode == 'SEL' toggle_select f elsif $mode == 'COM' run_command f else open_file f end #selectedix=ix end end |
#select_used_dirs ⇒ Object
687 688 689 690 691 |
# File 'lib/cygnus.rb', line 687 def select_used_dirs $title = "Used Directories" $files = $used_dirs.uniq #show_list end |
#select_visited_files ⇒ Object
show_list
692 693 694 695 696 697 698 |
# File 'lib/cygnus.rb', line 692 def select_visited_files # not yet a unique list, needs to be unique and have latest pushed to top $title = "Visited Files" files = $visited_files.uniq show_list files $title = nil end |
#selection_mode_toggle ⇒ Object
toggle mode to selection or not
In selection, pressed hotkey selects a file without opening, one can keep selecting
(or deselecting).
408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/cygnus.rb', line 408 def selection_mode_toggle if $mode == 'SEL' # we seem to be coming out of select mode with some files if $selected_files.size > 0 run_command $selected_files end $mode = nil else #$selection_mode = !$selection_mode $mode = 'SEL' end end |
#show_marks ⇒ Object
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/cygnus.rb', line 463 def show_marks list = [] $bookmarks.each_pair { |k, v| list << " #[fg=yellow, bold]#{k}#[/end] #[fg=green]#{v}#[/end]" } # s="#[fg=green]hello there#[fg=yellow, bg=black, dim]" config = {} longestval = $bookmarks.values.max_by(&:length) config[:title] = "Bookmarks" config[:width] = [longestval.length + 5, FFI::NCurses.COLS - 5].min $log.debug "XXX: LONGEST #{longestval}, #{longestval.length}" ch = padpopup list, config return unless ch #$bookmarks.each_pair { |k, v| puts "#{k.ljust(7)} => #{v}" } #puts #print "Enter bookmark to goto: " #ch = get_char goto_bookmark(ch) if ch =~ /^[0-9A-Z]$/ end |
#sort_menu ⇒ Object
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'lib/cygnus.rb', line 564 def lo = nil h = { :n => :newest, :a => :accessed, :o => :oldest, :l => :largest, :s => :smallest , :m => :name , :r => :rname, :d => :dirs, :c => :clear } ch, = "Sort Menu", h case when :newest lo="om" when :accessed lo="oa" when :oldest lo="Om" when :largest lo="OL" when :smallest lo="oL" when :name lo="on" when :rname lo="On" when :dirs lo="/" when :clear lo="" end ## This needs to persist and be a part of all listings, put in change_dir. $sorto = lo $files = `zsh -c 'print -rl -- *(#{lo}#{$hidden}M)'`.split("\n") if lo $title = nil #$files =$(eval "print -rl -- ${pattern}(${MFM_LISTORDER}$filterstr)") end |
#subcommand ⇒ Object
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 |
# File 'lib/cygnus.rb', line 817 def subcommand begin command = get_line "Enter command: " #command = gets().chomp #command = Readline::readline('>', true) return if command == "" rescue Exception => ex return end if command == "q" if $modified ch = get_single "Do you want to save bookmarks? (y/n): " #ch = get_char if ch == "y" $writing = true $quitting = true elsif ch == "n" $quitting = true print "Quitting without saving bookmarks" else perror "No action taken." end else $quitting = true end elsif command == "wq" $quitting = true $writing = true elsif command == "x" $quitting = true $writing = true if $modified elsif command == "p" c_system "echo $PWD | pbcopy" get_single "Stored PWD in clipboard (using pbcopy)" end end |
#TODOpost_cd ⇒ Object
TODO
733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
# File 'lib/cygnus.rb', line 733 def TODOpost_cd $patt=nil $sta = $cursor = 0 $title = nil if $selected_files.size > 0 $selected_files = [] end $visual_block_start = nil $stact = 0 screen_settings # i think this will screw with the dir_pos since it is not filename based. enhance_file_list revert_dir_pos end |
#toggle_menu ⇒ Object
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
# File 'lib/cygnus.rb', line 523 def h = { :h => :toggle_hidden, :c => :toggle_case, :l => :toggle_long_list , "1" => :toggle_columns, :p => :toggle_pager_mode, :e => :toggle_enhanced_list} ch, = "Toggle Menu", h case when :toggle_hidden #$hidden = $hidden ? nil : "D" $hidden = !$hidden c_refresh when :toggle_case #$ignorecase = $ignorecase ? "" : "i" $ignorecase = !$ignorecase c_refresh when :toggle_columns $gviscols = 3 if $gviscols == 1 #$long_listing = false if $gviscols > 1 x = $grows * $gviscols $pagesize = $pagesize==x ? $grows : x when :toggle_pager_mode $editor_mode = !$editor_mode if $editor_mode $default_command = nil else $default_command = ENV['MANPAGER'] || ENV['PAGER'] end when :toggle_enhanced_list $enhanced_mode = !$enhanced_mode when :toggle_long_list $long_listing = !$long_listing if $long_listing $gviscols = 1 $pagesize = $grows else x = $grows * $gviscols $pagesize = $pagesize==x ? $grows : x end c_refresh end end |
#toggle_select(f) ⇒ Object
toggle selection state of file
296 297 298 299 300 301 302 |
# File 'lib/cygnus.rb', line 296 def toggle_select f if $selected_files.index f $selected_files.delete f else $selected_files.push f end end |
#tree ⇒ Object
structure than files.
889 890 891 892 893 |
# File 'lib/cygnus.rb', line 889 def tree # Caution: use only for small projects, don't use in root. $title = "Full Tree" $files = `zsh -c 'print -rl -- **/*(#{$sorto}#{$hidden}M)'`.split("\n") end |
#unselect_all ⇒ Object
unselect all files
367 368 369 370 |
# File 'lib/cygnus.rb', line 367 def unselect_all $selected_files = [] $visual_mode = nil end |
#views ⇒ Object
867 868 869 870 871 872 873 874 875 876 877 |
# File 'lib/cygnus.rb', line 867 def views views=%w[/ om oa Om OL oL On on] viewlabels=%w[Dirs Newest Accessed Oldest Largest Smallest Reverse Name] $sorto = views[$viewctr] $title = viewlabels[$viewctr] $viewctr += 1 $viewctr = 0 if $viewctr > views.size $files = `zsh -c 'print -rl -- *(#{$sorto}#{$hidden}M)'`.split("\n") end |
#viminfo ⇒ Object
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
# File 'lib/cygnus.rb', line 1178 def viminfo file = File.("~/.viminfo") if File.exists? file $title = "Files from ~/.viminfo" #$files = `grep '^>' ~/.viminfo | cut -d ' ' -f 2- | sed "s#~#$HOME#g"`.split("\n") $files = `grep '^>' ~/.viminfo | cut -d ' ' -f 2- `.split("\n") $files.reject! {|x| x = File.(x); !File.exists?(x) } show_list end end |
#visual_block_clear ⇒ Object
1293 1294 1295 1296 1297 1298 1299 1300 1301 |
# File 'lib/cygnus.rb', line 1293 def visual_block_clear if $visual_block_start star = [$visual_block_start, $cursor].min fin = [$visual_block_start, $cursor].max $selected_files = $selected_files - $view[star..fin] end $visual_block_start = nil $visual_mode = nil end |
#visual_mode_toggle ⇒ Object
1286 1287 1288 1289 1290 1291 1292 |
# File 'lib/cygnus.rb', line 1286 def visual_mode_toggle $visual_mode = !$visual_mode if $visual_mode $visual_block_start = $cursor $selected_files.push $view[$cursor] end end |
#z_interface ⇒ Object
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 |
# File 'lib/cygnus.rb', line 1188 def z_interface file = File.("~/.z") if File.exists? file $title = "Directories from ~/.z" $files = `sort -rn -k2 -t '|' ~/.z | cut -f1 -d '|'`.split("\n") home = ENV['HOME'] $files.collect! do |f| f.sub(/#{home}/,"~") end show_list end end |