cygnus 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cygnus +53 -22
- data/lib/cygnus.rb +54 -0
- data/lib/cygnus/version.rb +1 -1
- metadata +4 -4
data/bin/cygnus
CHANGED
@@ -8,17 +8,18 @@
|
|
8
8
|
# Author: rkumar http://github.com/rkumar/mancurses/
|
9
9
|
# Date: 2011-11-09 - 16:59
|
10
10
|
# License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
11
|
-
# Last update: 2013-03-19
|
11
|
+
# Last update: 2013-03-19 14:02
|
12
12
|
#
|
13
13
|
# == CHANGES
|
14
14
|
# == BUGS
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
15
|
+
# x we have overridden textpad bindings yet they show / n gg etc.
|
16
|
+
# _ show form bindings too
|
17
|
+
# x our bindings from the hash do not show up..
|
18
18
|
# _ white line at bottom and right
|
19
19
|
#
|
20
20
|
# == TODO
|
21
21
|
#
|
22
|
+
# _ use BS to cycle files visited as in mancurses
|
22
23
|
# _ show how many files 1-5 or 15 etc
|
23
24
|
# _ toggle edit mode and view mode
|
24
25
|
# _ long listing toggle + other toggles
|
@@ -383,24 +384,6 @@ def full_indexed_list dir=Dir.pwd, config={}, &block
|
|
383
384
|
#alert "char got (#{ch.chr})"
|
384
385
|
chr = ch.chr
|
385
386
|
select_hint $viewport, chr
|
386
|
-
#ix = get_index chr
|
387
|
-
#if ix
|
388
|
-
#file = $viewport[ix]
|
389
|
-
#if file
|
390
|
-
#file = File.expand_path file
|
391
|
-
#if File.directory? file
|
392
|
-
#change_dir file
|
393
|
-
#next
|
394
|
-
#elsif File.file? file
|
395
|
-
#pad_display_file file, DefaultFileRenderer.new
|
396
|
-
#next
|
397
|
-
#else
|
398
|
-
#alert "Some new error has crept in. Neither file not directory: (#{file})"
|
399
|
-
#$log.warn "XXXXX: FILE Neither file not directory: (#{file})"
|
400
|
-
#end
|
401
|
-
#end
|
402
|
-
#else
|
403
|
-
#end
|
404
387
|
next
|
405
388
|
end
|
406
389
|
|
@@ -487,6 +470,11 @@ def pad_display_file filename, renderer, config={}, &block
|
|
487
470
|
window = VER::Window.new(layout)
|
488
471
|
form = RubyCurses::Form.new window
|
489
472
|
|
473
|
+
# maintain a stack of filename so we can backspace through them
|
474
|
+
fn = filename
|
475
|
+
fn = "#{Dir.pwd}/#{filename}" unless filename[0] == "/"
|
476
|
+
@file_stack << fn unless @file_stack.include? fn
|
477
|
+
|
490
478
|
listconfig = config[:listconfig] || {}
|
491
479
|
#listconfig[:list] = list
|
492
480
|
listconfig[:width] = width
|
@@ -518,9 +506,48 @@ def pad_display_file filename, renderer, config={}, &block
|
|
518
506
|
begin
|
519
507
|
while((ch = window.getchar()) != 999 )
|
520
508
|
|
509
|
+
# we need to show bindings if user does ? or M-?
|
521
510
|
case ch
|
511
|
+
|
512
|
+
when ?\C-j.getbyte(0), ?\C-n.getbyte(0)
|
513
|
+
# jump to next file so user does not need to go out and in again
|
514
|
+
$cursor += 1
|
515
|
+
if $view[$cursor]
|
516
|
+
_f = $view[$cursor]
|
517
|
+
lb.text(get_file_contents(_f))
|
518
|
+
lb.title(_f)
|
519
|
+
form.repaint
|
520
|
+
next
|
521
|
+
end
|
522
|
+
|
523
|
+
when ?\C-k.getbyte(0), ?\C-p.getbyte(0)
|
524
|
+
# jump to previous file so user does not need to go out and in again
|
525
|
+
$cursor -= 1
|
526
|
+
if $view[$cursor]
|
527
|
+
_f = $view[$cursor]
|
528
|
+
lb.text(get_file_contents(_f))
|
529
|
+
lb.title(_f)
|
530
|
+
form.repaint
|
531
|
+
next
|
532
|
+
end
|
522
533
|
when ?q.getbyte(0), ?\C-q.getbyte(0), 13, 10, 27, 2727
|
534
|
+
# close window on q or enter or double escape
|
523
535
|
break
|
536
|
+
when 127
|
537
|
+
# hitting backspace cycles through list of files viewed
|
538
|
+
# FIXME first time we have to hit BS 2 times since we get same file we are viewing
|
539
|
+
_f = @file_stack.pop
|
540
|
+
if _f
|
541
|
+
# push it to first
|
542
|
+
@file_stack.insert 0, _f
|
543
|
+
#lb.filename(_f)
|
544
|
+
lb.text(get_file_contents(_f))
|
545
|
+
form.repaint
|
546
|
+
next
|
547
|
+
else
|
548
|
+
#alert "No file to pop"
|
549
|
+
end
|
550
|
+
|
524
551
|
else
|
525
552
|
lb.handle_key ch
|
526
553
|
form.repaint
|
@@ -649,6 +676,7 @@ end
|
|
649
676
|
return ix
|
650
677
|
end
|
651
678
|
@dir_stack = []
|
679
|
+
@file_stack = []
|
652
680
|
def change_dir dir, filename=nil
|
653
681
|
@dir_stack << Dir.pwd unless @dir_stack.include? Dir.pwd
|
654
682
|
$sta = $cursor = 0
|
@@ -723,6 +751,7 @@ end
|
|
723
751
|
elsif text =~ /(archive|zip)/
|
724
752
|
return :zip
|
725
753
|
else
|
754
|
+
return :directory if File.directory? f
|
726
755
|
return :unknown
|
727
756
|
end
|
728
757
|
end
|
@@ -747,6 +776,8 @@ end
|
|
747
776
|
return t
|
748
777
|
when :zip
|
749
778
|
return `tar ztvf #{f}`.split("\n")
|
779
|
+
when :directory
|
780
|
+
return Dir.glob("*")
|
750
781
|
else
|
751
782
|
return ["unknown type", `file #{f}`]
|
752
783
|
end
|
data/lib/cygnus.rb
CHANGED
@@ -186,8 +186,42 @@ def columnate_with_indexing ary, sz
|
|
186
186
|
end
|
187
187
|
return buff
|
188
188
|
end
|
189
|
+
# print in columns
|
190
|
+
# ary - array of data
|
191
|
+
# sz - lines in one column
|
192
|
+
# This is the original which did not format or color, but since we cannot truncate unless
|
193
|
+
# we have unformatted data i need to mix the functionality into columnate_with_indexing
|
194
|
+
def columnate ary, sz
|
195
|
+
buff=Array.new
|
196
|
+
return buff if ary.nil? || ary.size == 0
|
197
|
+
|
198
|
+
# ix refers to the index in the complete file list, wherease we only show 60 at a time
|
199
|
+
ix=0
|
200
|
+
while true
|
201
|
+
## ctr refers to the index in the column
|
202
|
+
ctr=0
|
203
|
+
while ctr < sz
|
204
|
+
|
205
|
+
f = ary[ix]
|
206
|
+
# deleted truncate and pad part since we expect cols to be sized same
|
207
|
+
|
208
|
+
if buff[ctr]
|
209
|
+
buff[ctr] += f
|
210
|
+
else
|
211
|
+
buff[ctr] = f
|
212
|
+
end
|
213
|
+
|
214
|
+
ctr+=1
|
215
|
+
ix+=1
|
216
|
+
break if ix >= ary.size
|
217
|
+
end
|
218
|
+
break if ix >= ary.size
|
219
|
+
end
|
220
|
+
return buff
|
221
|
+
end
|
189
222
|
## formats the data with number, mark and details
|
190
223
|
def format ary
|
224
|
+
alert "deprecated, can be removed if not called"
|
191
225
|
#buff = Array.new
|
192
226
|
buff = Array.new(ary.size)
|
193
227
|
return buff if ary.nil? || ary.size == 0
|
@@ -443,6 +477,26 @@ def show_marks
|
|
443
477
|
#ch = get_char
|
444
478
|
goto_bookmark(ch) if ch =~ /^[0-9A-Z]$/
|
445
479
|
end
|
480
|
+
def print_help
|
481
|
+
h = @bindings
|
482
|
+
row = 1
|
483
|
+
list = []
|
484
|
+
longestval = h.values.max_by(&:length)
|
485
|
+
llen = longestval.length
|
486
|
+
# they must all be of same size so i can easily columnate
|
487
|
+
h.each_pair { |k, v| list << " #[fg=yellow, bold]#{k.ljust(6)}#[/end] #[fg=green]#{v.ljust(llen)}#[/end]" }
|
488
|
+
lines = FFI::NCurses.LINES - row
|
489
|
+
list = columnate list, lines - 2
|
490
|
+
config = {}
|
491
|
+
config[:row] = row
|
492
|
+
config[:col] = 1
|
493
|
+
config[:title] = "Key Bindings"
|
494
|
+
#config[:width] = [longestval.length + 5, FFI::NCurses.COLS - 5].min
|
495
|
+
config[:width] = FFI::NCurses.COLS - config[:col]
|
496
|
+
config[:height] = lines
|
497
|
+
ch = padpopup list, config
|
498
|
+
return unless ch
|
499
|
+
end
|
446
500
|
# MENU MAIN -- keep consistent with zfm
|
447
501
|
def main_menu
|
448
502
|
h = {
|
data/lib/cygnus/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cygnus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
segments:
|
78
78
|
- 0
|
79
|
-
hash: -
|
79
|
+
hash: -4394376758347789343
|
80
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
segments:
|
87
87
|
- 0
|
88
|
-
hash: -
|
88
|
+
hash: -4394376758347789343
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
91
|
rubygems_version: 1.8.25
|