cetus 0.1.24 → 0.1.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cetus +179 -42
  3. data/cetus.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe8c1244b0c3e4c41eb6f186f13a2145330c3243de099db9a91bac5a87f0b1c6
4
- data.tar.gz: e732da1943a5b7ab651c736a6d56bd645ce9d58b9dbf1857efcb97713563c2e1
3
+ metadata.gz: e330d082b6cacb3bc2bb8294f240e1dbe52c020f67036e7749c23975ad74315e
4
+ data.tar.gz: 233d66a84c34f2909ced5d9d0c2a7ee9b6f251f812190cd51fa74df0a7d685ad
5
5
  SHA512:
6
- metadata.gz: 16cab047cb3fa5b2a9de8b25a8c3fe450ef9527896b19af2b5cd9d6ff5b554381c8b012dd21b2f9477ff8f00e080b3cf25d359e5c85103c3a777faa0ae1c171c
7
- data.tar.gz: 106ccedd0121858ddd1a867a9d2c875c8ab9fd1b6cba34062fbeed6ec256c80032f23b9363ea78c018ab861d8eb189c91bde3b373d1963ea16b656a1c0e40597
6
+ metadata.gz: 167c052b0de647248274ae297dd0dc7ec02a1ed597abd93622a53ca65b06de13723f466d0476ef52aba505ebe2b5d44eb59ecd8c095d47b7bea792d8041ea5e9
7
+ data.tar.gz: f83e861550b178f4eedc21138645df39fea00f55fd450353f12c6e797137f1902646859bb273238f1219611bfb092292646c3befd7b421757bdc3f4a193c9f6a
data/bin/cetus CHANGED
@@ -6,7 +6,7 @@
6
6
  # Author: rkumar http://github.com/rkumar/cetus/
7
7
  # Date: 2013-02-17 - 17:48
8
8
  # License: GPL
9
- # Last update: 2019-03-18 14:02
9
+ # Last update: 2019-03-20 11:43
10
10
  # --------------------------------------------------------------------------- #
11
11
  # cetus.rb Copyright (C) 2012-2019 rahul kumar
12
12
  # == CHANGELOG
@@ -35,9 +35,7 @@ require 'fileutils'
35
35
 
36
36
  # 2019-02-20 - added so alt-screen is used
37
37
  system 'tput smcup'
38
- VERSION = '0.1.24.0'.freeze
39
- O_CONFIG = true
40
- # CONFIG_FILE = '~/.lyrainfo'.freeze
38
+ VERSION = '0.1.26.0'.freeze
41
39
  CONFIG_FILE = '~/.config/cetus/conf.yml'.freeze
42
40
 
43
41
  $bindings = {}
@@ -52,6 +50,7 @@ $bindings = {
52
50
  'C-o' => 'edit_current',
53
51
  'C-s' => 'toggle_select',
54
52
  'C-r' => 'reduce',
53
+ 'C-g' => 'debug_vars',
55
54
  '@' => 'selection_mode_toggle',
56
55
  'M-a' => 'select_all',
57
56
  'M-A' => 'unselect_all',
@@ -281,10 +280,10 @@ $bookmarks = {}
281
280
  $mode = nil
282
281
  $glines = `tput lines`.to_i
283
282
  $gcols = `tput cols`.to_i
284
- $grows = $glines - 3
285
- $pagesize = 60
283
+ $grows = $glines - 3 # can be a func
284
+ # $pagesize = 60
286
285
  $gviscols = 3
287
- $pagesize = $grows * $gviscols
286
+ $pagesize = $grows * $gviscols # can be a func
288
287
  $stact = 0
289
288
  # $editor_mode = true
290
289
  $editor_mode = false # changed 2018-03-12 - so we start in pager mode
@@ -328,8 +327,10 @@ $default_sort_order = 'om'
328
327
  $sorto = $default_sort_order
329
328
  $viewctr = 0
330
329
  $history = []
330
+ ## sta is where view (viewport) begins, cursor is current row/file
331
331
  $sta = $cursor = 0
332
332
  $visual_mode = false
333
+ $status_color = 4 # status line, can be 2 3 4 5 6
333
334
  # $help = "#{BOLD}1-9a-zA-Z#{BOLD_OFF} Select #{BOLD}/#{BOLD_OFF} Grep #{BOLD}'#{BOLD_OFF} First char #{BOLD}M-n/p#{BOLD_OFF} Paging #{BOLD}!#{BOLD_OFF} Execute #{BOLD}@#{BOLD_OFF} Selection Mode #{BOLD}q#{BOLD_OFF} Quit"
334
335
 
335
336
  # Menubar on top of screen
@@ -348,22 +349,28 @@ def run
348
349
 
349
350
  fl = $files.size
350
351
 
351
- selectedix = nil
352
- $patt = ''
352
+ # selectedix = nil
353
+ # $patt = ''
354
+ $patt = nil
353
355
  $sta = 0
354
356
  loop do
355
- i = 0
357
+ # i = 0
356
358
  $view = if $patt
357
359
  if $ignorecase
358
360
  $files.grep(/#{$patt}/i)
359
361
  else
360
362
  $files.grep(/#{$patt}/)
361
- end
363
+ end
362
364
  else
363
365
  $files
364
366
  end
365
367
  fl = $view.size
366
368
  $sta = 0 if $sta >= fl || $sta < 0
369
+ # 2019-03-18 - added to ensure cursor not going OOB when next_page
370
+ $cursor = 0 if $cursor >= fl || $cursor < 0
371
+ # $sta = $cursor if $sta > $cursor
372
+ $cursor = $sta if $sta > $cursor
373
+
367
374
  $viewport = $view[$sta, $pagesize]
368
375
  fin = $sta + $viewport.size
369
376
  $title ||= Dir.pwd.sub(home, '~')
@@ -390,13 +397,31 @@ def run
390
397
  buff.each { |line| print line, "\n" }
391
398
  print
392
399
 
393
-
394
400
  # prompt
395
401
  # print "#{$files.size}, #{view.size} sta=#{sta} (#{patt}): "
396
- _mm = ''
397
- _mm = "[#{$mode}] " if $mode
398
- print "\r#{_mm}#{$patt} #{GREEN}#{$message}#{CLEAR} >"
402
+ v_mm = ''
403
+ v_mm = "[#{$mode}] " if $mode
404
+ cf = current_file
405
+ $message = "No file highlighted (#{cf})" if cf and !$highlighted_a_column
406
+ $message = ' | No matches. Press ESCAPE' if $patt && !cf
407
+ # 2019-03-19 - take cursor to last line
408
+ system "tput cup #{$glines} 0"
409
+ # system "tput cup #{$glines} #{$gcols - cfl - 10}"
410
+ print "\e[33;4%sm%*s" % [$status_color || '1', $gcols, " "]
411
+
412
+ # sometimes due to search, there is no file
413
+ if cf
414
+ cfl = cf.size
415
+ # print right alighed
416
+ system "tput cup #{$glines} #{$gcols - cfl - 10}"
417
+ # print "#{REVERSE}#{cf}#{CLEAR}"
418
+ print "#{cf}"
419
+ end
420
+ # print "\r#{v_mm}#{$patt} #{GREEN}#{$message}#{CLEAR} >"
421
+ # move to beginning of line, reset text mode after printing
422
+ print "\r#{v_mm}#{$patt}#{$message}\e[m"
399
423
  ch = get_char
424
+ $highlighted_a_column = false
400
425
  # puts
401
426
  # break if ch == "q"
402
427
  # elsif ch =~ /^[1-9a-zA-Z]$/
@@ -408,6 +433,7 @@ def run
408
433
  ctr = 0
409
434
  elsif ch == 'BACKSPACE'
410
435
  $patt = $patt[0..-2] if $patt && !$patt.empty?
436
+ $message = $patt = nil if $patt == ''
411
437
  ctr = 0
412
438
  else
413
439
  # binding = $bindings[ch]
@@ -469,6 +495,9 @@ def columnate(ary, sz)
469
495
  buff = []
470
496
  return buff if ary.nil? || ary.empty?
471
497
 
498
+ # 2019-03-19 - just to make sure highlighted column is visible
499
+ $highlighted_a_column = false
500
+
472
501
  # determine width based on number of files to show
473
502
  # if less than sz then 1 col and full width
474
503
  #
@@ -514,6 +543,7 @@ def columnate(ary, sz)
514
543
  ## we do the coloring after trunc so ANSI escpe seq does not get get
515
544
  if ix + $sta == $cursor
516
545
  f = "#{CURSOR_COLOR}#{f}#{CLEAR}"
546
+ $highlighted_a_column = true
517
547
  elsif linecolor
518
548
  f = "#{linecolor}#{f}#{CLEAR}"
519
549
  end
@@ -525,6 +555,7 @@ def columnate(ary, sz)
525
555
  # f = "#{CURSOR_COLOR}#{f}#{CLEAR}" if ix + $sta == $cursor
526
556
  if ix + $sta == $cursor
527
557
  f = "#{CURSOR_COLOR}#{f}#{CLEAR}"
558
+ $highlighted_a_column = true
528
559
  else
529
560
  f = "#{linecolor}#{f}#{CLEAR}" if linecolor
530
561
  end
@@ -582,6 +613,8 @@ def _format(ary)
582
613
  last = f[-1]
583
614
  stat = File.stat(f.chop) if last == ' ' || last == '@' || last == '*'
584
615
  end
616
+ # this is for saved directories etc which are shortened
617
+ stat ||= File.stat(File.expand_path(f))
585
618
  f = format('%10s %s %s', readable_file_size(stat.size, 1),
586
619
  date_format(stat.mtime), f)
587
620
  rescue Exception => e
@@ -766,6 +799,7 @@ def change_dir(f, pos = nil)
766
799
  return
767
800
  end
768
801
  $visited_dirs.insert(0, Dir.pwd)
802
+ save_dir_pos # added 2019-03-20 - so we get to same file
769
803
  f = File.expand_path(f)
770
804
  Dir.chdir f
771
805
  $filterstr ||= 'M'
@@ -882,8 +916,18 @@ def command_mode
882
916
  $mode = 'COM'
883
917
  end
884
918
 
919
+ # go to parent dir, and maintain cursor on the dir we came out of
885
920
  def goto_parent_dir
921
+ # 2019-03-20 - when changing to parent, we need to keep cursor on
922
+ # parent dir, not first
923
+ curr = File.basename(Dir.pwd)
924
+
886
925
  change_dir '..'
926
+
927
+ # get index of child dir in this dir, and set cursor to it.
928
+ index = $files.index(curr + '/')
929
+ pause "WARNING: Could not find #{curr} in this directory." unless index
930
+ $cursor = index if index
887
931
  end
888
932
 
889
933
  def goto_home_dir
@@ -934,23 +978,31 @@ end
934
978
 
935
979
  ## take regex from user, to run on files on screen, user can filter file names
936
980
  def enter_regex
937
- print 'Enter (regex) pattern: '
938
- # $patt = gets().chomp
939
- $patt = Readline.readline('>', true)
940
- ctr = 0
981
+ # print 'Enter (regex) pattern: '
982
+ # move to beginning of line, and clear till EOL
983
+ print "\r\e[K"
984
+ $patt = Readline.readline('/', true)
941
985
  end
942
986
 
987
+ # page/scroll down.
988
+ # TODO: 2019-03-18 - cursor needs to be updated
943
989
  def next_page
944
990
  $sta += $pagesize
991
+ $cursor += $pagesize
992
+ $sta = $cursor if $sta > $cursor
993
+ # FIXME this is sometimes correct, but in short cases, cursor no longer refers
994
+ # to a file. also after cycling, it no longer has a file.
945
995
  end
946
996
 
997
+ # TODO: 2019-03-18 - cursor needs to be updated
947
998
  def prev_page
948
999
  $sta -= $pagesize
1000
+ $cursor -= $pagesize
949
1001
  end
950
1002
 
951
1003
  # print help on key-bindings
952
1004
  # 2019-03-08 - write to temp file and user PAGER
953
- def print_help
1005
+ def old_print_help
954
1006
  require 'tempfile'
955
1007
  file = Tempfile.new('help')
956
1008
  begin
@@ -974,7 +1026,67 @@ def print_help
974
1026
  file.close
975
1027
  file.unlink
976
1028
  end
977
- end #
1029
+ end
1030
+
1031
+ def print_help
1032
+ page_with_tempfile do |file|
1033
+ file.puts ' HELP'
1034
+
1035
+ file.puts
1036
+ file.puts 'To open a file or dir press 1-9 a-z A-Z (on left of file)'
1037
+ file.puts 'Ctrl-s to select file under cursor'
1038
+ file.puts 'Selection Mode: Each selection adds to selection list (toggles)'
1039
+ file.puts ' Execute commands on selected files. e.g D C-x '
1040
+ file.puts ' Upon exiting mode, selection is cleared'
1041
+ file.puts 'Use left and right arrows to move through directories'
1042
+ file.puts
1043
+ ary = []
1044
+ # TODO: 2019-03-19 - replace _ with space in value
1045
+ # TODO: 2019-03-19 - if : then show text after colon
1046
+ $bindings.each_pair { |k, v| ary.push "#{k.ljust(7)} => #{v}" }
1047
+ # FIXME this works but not properly when long_listing is true.
1048
+ # We should avoid using columnate as there are several file related things.
1049
+ ary = columnate ary, (ary.size/2)+1
1050
+ ary.each { |line| file.puts line }
1051
+ end
1052
+ end
1053
+
1054
+ def page_stat_for_file
1055
+ stat = %x[ stat #{current_file} ]
1056
+ return unless stat
1057
+
1058
+ page_with_tempfile do |file|
1059
+ file.puts stat
1060
+ end
1061
+
1062
+ end
1063
+
1064
+ def page_with_tempfile
1065
+ require 'tempfile'
1066
+ file = Tempfile.new('cetus')
1067
+ begin
1068
+ yield file
1069
+ file.flush
1070
+ system "$PAGER #{file.path}"
1071
+ rescue
1072
+ file.close
1073
+ file.unlink
1074
+ end
1075
+ end
1076
+
1077
+ def debug_vars
1078
+ page_with_tempfile do |file|
1079
+ file.puts 'DEBUG VARIABLES ARE:'
1080
+ file.puts
1081
+ file.puts "sta #{$sta}"
1082
+ file.puts "cursor #{$cursor}"
1083
+ file.puts "stact #{$stact}"
1084
+ file.puts "viewport.size #{$viewport.size}"
1085
+ file.puts "pagesize #{$pagesize}"
1086
+ file.puts "view.size #{$view.size}"
1087
+ file.puts "file #{current_file}"
1088
+ end
1089
+ end
978
1090
 
979
1091
  def view_bookmarks
980
1092
  puts
@@ -1441,7 +1553,7 @@ def subcommand
1441
1553
  $writing = true if $modified
1442
1554
  elsif command == 'e'
1443
1555
  edit_current
1444
- elsif command == 'h' or command == 'help' or command = '?'
1556
+ elsif command == 'h' or command == 'help' or command == '?'
1445
1557
  print_help
1446
1558
  elsif command == 'p'
1447
1559
  system 'echo $PWD | pbcopy'
@@ -1613,7 +1725,7 @@ def screen_settings
1613
1725
  $glines = `tput lines`.to_i
1614
1726
  $gcols = `tput cols`.to_i
1615
1727
  $grows = $glines - 3
1616
- $pagesize = 60
1728
+ # $pagesize = 60
1617
1729
  # $gviscols = 3
1618
1730
  $pagesize = $grows * $gviscols
1619
1731
  end
@@ -1654,8 +1766,8 @@ end
1654
1766
  def file_actions(action = nil)
1655
1767
  # only add dtrx for gz
1656
1768
  h = { d: :delete, m: :move, r: :rename, v: ENV['EDITOR'] || :vim,
1657
- c: :copy, C: :chdir, W: :remspace, e: :execute,
1658
- l: :less, s: :most, f: :file, o: :open, x: :dtrx, z: :zip }
1769
+ c: :copy, C: :chdir, W: :remspace, e: :execute, s: :page_stat_for_file,
1770
+ l: :less, p: :most, f: :file, o: :open, x: :dtrx, z: :zip }
1659
1771
  # acttext = h[action.to_sym] || action
1660
1772
  acttext = action || ''
1661
1773
  file = nil
@@ -1822,6 +1934,10 @@ def file_actions(action = nil)
1822
1934
  refresh
1823
1935
  when :execute
1824
1936
  execute
1937
+ when :page_stat_for_file
1938
+ 1
1939
+ # already been executed by menu
1940
+ # We could have just put 'stat' in the menu but that doesn't look so nice
1825
1941
  else
1826
1942
  return unless menu_text
1827
1943
 
@@ -1963,20 +2079,23 @@ end
1963
2079
  def pipe; end
1964
2080
 
1965
2081
  ## some cursor movement functions
1966
- ##
1967
- #
2082
+ # TODO: 2019-03-18 - cursor should also be updated
2083
+ # sta is not updated when cursor > viewport.size and sta is still 0
1968
2084
  def cursor_scroll_dn
1969
2085
  moveto(pos + MSCROLL)
1970
2086
  end
1971
2087
 
2088
+ # TODO: 2019-03-18 - cursor should also be updated
1972
2089
  def cursor_scroll_up
1973
2090
  moveto(pos - MSCROLL)
1974
2091
  end
1975
2092
 
2093
+ # TODO: 2019-03-18 - cursor and sta should also be updated if page changes
1976
2094
  def cursor_dn
1977
2095
  moveto(pos + 1)
1978
2096
  end
1979
2097
 
2098
+ # TODO: 2019-03-18 - cursor and sta should also be updated if page changes
1980
2099
  def cursor_up
1981
2100
  moveto(pos - 1)
1982
2101
  end
@@ -1986,25 +2105,40 @@ def pos
1986
2105
  end
1987
2106
 
1988
2107
  # move cursor to given position/line
1989
- def moveto(pos)
2108
+ # $sta should also move
2109
+ def moveto(position)
1990
2110
  orig = $cursor
1991
- $cursor = pos
2111
+ $cursor = position
1992
2112
  $cursor = [$cursor, $view.size - 1].min
1993
2113
  $cursor = [$cursor, 0].max
2114
+ # 2019-03-18 - adding sta
2115
+ # $sta = position - only when page flips and file not visible
2116
+ # FIXME not correct, it must stop at end or correctly cycle
2117
+ # sta goes to 0 but cursor remains at 70
2118
+ # viewport.size may be wrong here, maybe should be pagesize only
2119
+ if $cursor - $sta >= $pagesize
2120
+ $sta += $pagesize
2121
+ # elsif $sta - $cursor >= $viewport.size
2122
+ end
2123
+ if $sta > $cursor
2124
+ $sta -= $pagesize
2125
+ # $sta = $cursor
2126
+ end
2127
+
1994
2128
  star = [orig, $cursor].min
1995
2129
  fin = [orig, $cursor].max
1996
- if $visual_mode
1997
- # PWD has to be there in selction
1998
- if selected? current_file
1999
- # this depends on the direction
2000
- # $selected_files = $selected_files - $view[star..fin]
2001
- remove_from_selection $view[star..fin]
2002
- ## current row remains in selection always.
2003
- add_to_selection current_file
2004
- else
2005
- # $selected_files.concat $view[star..fin]
2006
- add_to_selection $view[star..fin]
2007
- end
2130
+ return unless $visual_mode
2131
+
2132
+ # PWD has to be there in selction
2133
+ if selected? current_file
2134
+ # this depends on the direction
2135
+ # $selected_files = $selected_files - $view[star..fin]
2136
+ remove_from_selection $view[star..fin]
2137
+ ## current row remains in selection always.
2138
+ add_to_selection current_file
2139
+ else
2140
+ # $selected_files.concat $view[star..fin]
2141
+ add_to_selection $view[star..fin]
2008
2142
  end
2009
2143
  end
2010
2144
 
@@ -2120,12 +2254,15 @@ def filetype(f)
2120
2254
  nil
2121
2255
  end
2122
2256
 
2257
+ # save offset in directory so we can revert to it when we return
2123
2258
  def save_dir_pos
2124
- return if $sta == 0 && $cursor == 0
2259
+ # the next line meant that it would not save first directory.
2260
+ # return if $sta == 0 && $cursor == 0
2125
2261
 
2126
2262
  $dir_position[Dir.pwd] = [$sta, $cursor]
2127
2263
  end
2128
2264
 
2265
+ # revert to the position we were at in this directory
2129
2266
  def revert_dir_pos
2130
2267
  $sta = 0
2131
2268
  $cursor = 0
data/cetus.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'cetus'
8
- spec.version = '0.1.24'
8
+ spec.version = '0.1.26'
9
9
  spec.authors = ['Rahul Kumar']
10
10
  spec.email = ['oneness.univ@gmail.com']
11
11
  spec.description = %q{lightning fast file navigator}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cetus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.24
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rahul Kumar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2019-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler