diakonos 0.8.5 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +15 -0
- data/README +2 -3
- data/diakonos-256-colour.conf +8 -0
- data/diakonos.conf +67 -11
- data/lib/diakonos.rb +563 -267
- data/lib/diakonos/buffer.rb +205 -62
- data/lib/diakonos/readline.rb +229 -193
- data/test/buffer-test.rb +6 -6
- metadata +5 -6
- data/home-on-save.rb +0 -6
data/lib/diakonos/buffer.rb
CHANGED
@@ -346,7 +346,10 @@ class Buffer
|
|
346
346
|
end
|
347
347
|
|
348
348
|
def selection_mark
|
349
|
-
|
349
|
+
@text_marks[ SELECTION ]
|
350
|
+
end
|
351
|
+
def selecting?
|
352
|
+
!!selection_mark
|
350
353
|
end
|
351
354
|
|
352
355
|
def select_current_line
|
@@ -360,6 +363,11 @@ class Buffer
|
|
360
363
|
@lines[ @last_row ]
|
361
364
|
end
|
362
365
|
|
366
|
+
def select_all
|
367
|
+
anchorSelection( 0, 0, DONT_DISPLAY )
|
368
|
+
cursorTo( @lines.length - 1, @lines[ -1 ].length, DO_DISPLAY )
|
369
|
+
end
|
370
|
+
|
363
371
|
def select( from_regexp, to_regexp, include_ending = true )
|
364
372
|
start_row = nil
|
365
373
|
|
@@ -721,7 +729,7 @@ class Buffer
|
|
721
729
|
paste str, @indent_closers
|
722
730
|
cursorTo r, c
|
723
731
|
if /%_/ === str
|
724
|
-
find( [ /%_/ ], :down, '', CHOICE_YES_AND_STOP )
|
732
|
+
find( [ /%_/ ], :direction => :down, :replacement => '', :auto_choice => CHOICE_YES_AND_STOP )
|
725
733
|
end
|
726
734
|
else
|
727
735
|
@diakonos.log h[ :regexp ].inspect + " does not match '#{line}'"
|
@@ -730,19 +738,104 @@ class Buffer
|
|
730
738
|
end
|
731
739
|
|
732
740
|
def collapseWhitespace
|
733
|
-
|
741
|
+
if selection_mark
|
742
|
+
removeSelection DONT_DISPLAY
|
743
|
+
end
|
734
744
|
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
+
line = @lines[ @last_row ]
|
746
|
+
head = line[ 0...@last_col ]
|
747
|
+
tail = line[ @last_col..-1 ]
|
748
|
+
new_head = head.sub( /\s+$/, '' )
|
749
|
+
new_line = new_head + tail.sub( /^\s+/, ' ' )
|
750
|
+
if new_line != line
|
751
|
+
takeSnapshot( TYPING )
|
752
|
+
@lines[ @last_row ] = new_line
|
753
|
+
cursorTo( @last_row, @last_col - ( head.length - new_head.length ) )
|
754
|
+
setModified
|
755
|
+
end
|
756
|
+
end
|
757
|
+
|
758
|
+
def selected_lines
|
759
|
+
selection = selection_mark
|
760
|
+
if selection
|
761
|
+
if selection.end_col == 0
|
762
|
+
end_row = selection.end_row - 1
|
763
|
+
else
|
764
|
+
end_row = selection.end_row
|
765
|
+
end
|
766
|
+
@lines[ selection.start_row..end_row ]
|
767
|
+
else
|
768
|
+
[ @lines[ @last_row ] ]
|
769
|
+
end
|
770
|
+
end
|
771
|
+
|
772
|
+
def columnize( delimiter = /=>?|:|,/, num_spaces_padding = 1 )
|
773
|
+
takeSnapshot
|
774
|
+
|
775
|
+
lines = selected_lines
|
776
|
+
column_width = 0
|
777
|
+
lines.each do |line|
|
778
|
+
pos = ( line =~ delimiter )
|
779
|
+
if pos
|
780
|
+
column_width = [ pos, column_width ].max
|
781
|
+
end
|
782
|
+
end
|
783
|
+
|
784
|
+
padding = ' ' * num_spaces_padding
|
785
|
+
one_modified = false
|
786
|
+
|
787
|
+
lines.each do |line|
|
788
|
+
old_line = line.dup
|
789
|
+
if line =~ /^(.+?)(#{delimiter.source})(.*)$/
|
790
|
+
pre = $1
|
791
|
+
del = $2
|
792
|
+
post = $3
|
793
|
+
if pre !~ /\s$/
|
794
|
+
del = " #{del}"
|
795
|
+
end
|
796
|
+
if post !~ /^\s/
|
797
|
+
del = "#{del} "
|
798
|
+
end
|
799
|
+
del.sub!( /^\s+/, ' ' * num_spaces_padding )
|
800
|
+
del.sub!( /\s+$/, ' ' * num_spaces_padding )
|
801
|
+
line.replace( ( "%-#{column_width}s" % pre ) + del + post )
|
745
802
|
end
|
803
|
+
one_modified ||= ( line != old_line )
|
804
|
+
end
|
805
|
+
|
806
|
+
if one_modified
|
807
|
+
setModified
|
808
|
+
end
|
809
|
+
end
|
810
|
+
|
811
|
+
def comment_out
|
812
|
+
takeSnapshot
|
813
|
+
one_modified = false
|
814
|
+
selected_lines.each do |line|
|
815
|
+
old_line = line.dup
|
816
|
+
line.gsub!( /^(\s*)/, "\\1" + @settings[ "lang.#{@language}.comment_string" ].to_s )
|
817
|
+
line << @settings[ "lang.#{@language}.comment_close_string" ].to_s
|
818
|
+
one_modified ||= ( line != old_line )
|
819
|
+
end
|
820
|
+
if one_modified
|
821
|
+
setModified
|
822
|
+
end
|
823
|
+
end
|
824
|
+
|
825
|
+
def uncomment
|
826
|
+
takeSnapshot
|
827
|
+
comment_string = Regexp.escape( @settings[ "lang.#{@language}.comment_string" ].to_s )
|
828
|
+
comment_close_string = Regexp.escape( @settings[ "lang.#{@language}.comment_close_string" ].to_s )
|
829
|
+
one_modified = false
|
830
|
+
selected_lines.each do |line|
|
831
|
+
old_line = line.dup
|
832
|
+
line.gsub!( /^(\s*)#{comment_string}/, "\\1" )
|
833
|
+
line.gsub!( /#{comment_close_string}$/, '' )
|
834
|
+
one_modified ||= ( line != old_line )
|
835
|
+
end
|
836
|
+
if one_modified
|
837
|
+
setModified
|
838
|
+
end
|
746
839
|
end
|
747
840
|
|
748
841
|
def deleteLine
|
@@ -761,7 +854,7 @@ class Buffer
|
|
761
854
|
cursorTo( row, 0 )
|
762
855
|
setModified
|
763
856
|
|
764
|
-
|
857
|
+
retval
|
765
858
|
end
|
766
859
|
|
767
860
|
def deleteToEOL
|
@@ -800,11 +893,15 @@ class Buffer
|
|
800
893
|
def lineAt( y )
|
801
894
|
row = @top_line + y
|
802
895
|
if row < 0
|
803
|
-
|
896
|
+
nil
|
804
897
|
else
|
805
|
-
|
898
|
+
@lines[ row ]
|
806
899
|
end
|
807
900
|
end
|
901
|
+
|
902
|
+
def current_line
|
903
|
+
@lines[ @last_row ]
|
904
|
+
end
|
808
905
|
|
809
906
|
# Returns true iff the given column, x, is less than the length of the given line, y.
|
810
907
|
def inLine( x, y )
|
@@ -838,11 +935,11 @@ class Buffer
|
|
838
935
|
end
|
839
936
|
|
840
937
|
def currentRow
|
841
|
-
|
938
|
+
@last_row
|
842
939
|
end
|
843
940
|
|
844
941
|
def currentColumn
|
845
|
-
|
942
|
+
@last_col
|
846
943
|
end
|
847
944
|
|
848
945
|
# Returns the amount the view was actually panned.
|
@@ -1318,11 +1415,17 @@ class Buffer
|
|
1318
1415
|
# split across newline characters. Once the first element is found,
|
1319
1416
|
# each successive element must match against lines following the first
|
1320
1417
|
# element.
|
1321
|
-
def find( regexps,
|
1418
|
+
def find( regexps, options = {} )
|
1322
1419
|
return if regexps.nil?
|
1323
1420
|
regexp = regexps[ 0 ]
|
1324
1421
|
return if regexp == nil or regexp == //
|
1325
1422
|
|
1423
|
+
direction = options[ :direction ]
|
1424
|
+
replacement = options[ :replacement ]
|
1425
|
+
auto_choice = options[ :auto_choice ]
|
1426
|
+
from_row = options[ :starting_row ] || @last_row
|
1427
|
+
from_col = options[ :starting_col ] || @last_col
|
1428
|
+
|
1326
1429
|
if direction == :opposite
|
1327
1430
|
case @last_search_direction
|
1328
1431
|
when :up
|
@@ -1343,10 +1446,10 @@ class Buffer
|
|
1343
1446
|
if direction == :down
|
1344
1447
|
# Check the current row first.
|
1345
1448
|
|
1346
|
-
if index = @lines[
|
1449
|
+
if index = @lines[ from_row ].index( regexp, ( @last_finding ? @last_finding.start_col : from_col ) + 1 )
|
1347
1450
|
match = Regexp.last_match
|
1348
1451
|
found_text = match[ 0 ]
|
1349
|
-
finding = Finding.new(
|
1452
|
+
finding = Finding.new( from_row, index, from_row, index + found_text.length )
|
1350
1453
|
if finding.match( regexps, @lines )
|
1351
1454
|
throw :found
|
1352
1455
|
else
|
@@ -1356,7 +1459,7 @@ class Buffer
|
|
1356
1459
|
|
1357
1460
|
# Check below the cursor.
|
1358
1461
|
|
1359
|
-
( (
|
1462
|
+
( (from_row + 1)...@lines.length ).each do |i|
|
1360
1463
|
if index = @lines[ i ].index( regexp )
|
1361
1464
|
match = Regexp.last_match
|
1362
1465
|
found_text = match[ 0 ]
|
@@ -1373,7 +1476,7 @@ class Buffer
|
|
1373
1476
|
|
1374
1477
|
wrapped = true
|
1375
1478
|
|
1376
|
-
( 0
|
1479
|
+
( 0...from_row ).each do |i|
|
1377
1480
|
if index = @lines[ i ].index( regexp )
|
1378
1481
|
match = Regexp.last_match
|
1379
1482
|
found_text = match[ 0 ]
|
@@ -1388,12 +1491,12 @@ class Buffer
|
|
1388
1491
|
|
1389
1492
|
# And finally, the other side of the current row.
|
1390
1493
|
|
1391
|
-
#if index = @lines[
|
1392
|
-
if index = @lines[
|
1393
|
-
if index <= ( @last_finding ? @last_finding.start_col :
|
1494
|
+
#if index = @lines[ from_row ].index( regexp, ( @last_finding ? @last_finding.start_col : from_col ) - 1 )
|
1495
|
+
if index = @lines[ from_row ].index( regexp )
|
1496
|
+
if index <= ( @last_finding ? @last_finding.start_col : from_col )
|
1394
1497
|
match = Regexp.last_match
|
1395
1498
|
found_text = match[ 0 ]
|
1396
|
-
finding = Finding.new(
|
1499
|
+
finding = Finding.new( from_row, index, from_row, index + found_text.length )
|
1397
1500
|
if finding.match( regexps, @lines )
|
1398
1501
|
throw :found
|
1399
1502
|
else
|
@@ -1405,11 +1508,11 @@ class Buffer
|
|
1405
1508
|
elsif direction == :up
|
1406
1509
|
# Check the current row first.
|
1407
1510
|
|
1408
|
-
col_to_check = ( @last_finding ? @last_finding.end_col :
|
1409
|
-
if ( col_to_check >= 0 ) and ( index = @lines[
|
1511
|
+
col_to_check = ( @last_finding ? @last_finding.end_col : from_col ) - 1
|
1512
|
+
if ( col_to_check >= 0 ) and ( index = @lines[ from_row ][ 0...col_to_check ].rindex( regexp ) )
|
1410
1513
|
match = Regexp.last_match
|
1411
1514
|
found_text = match[ 0 ]
|
1412
|
-
finding = Finding.new(
|
1515
|
+
finding = Finding.new( from_row, index, from_row, index + found_text.length )
|
1413
1516
|
if finding.match( regexps, @lines )
|
1414
1517
|
throw :found
|
1415
1518
|
else
|
@@ -1419,7 +1522,7 @@ class Buffer
|
|
1419
1522
|
|
1420
1523
|
# Check above the cursor.
|
1421
1524
|
|
1422
|
-
(
|
1525
|
+
(from_row - 1).downto( 0 ) do |i|
|
1423
1526
|
if index = @lines[ i ].rindex( regexp )
|
1424
1527
|
match = Regexp.last_match
|
1425
1528
|
found_text = match[ 0 ]
|
@@ -1436,7 +1539,7 @@ class Buffer
|
|
1436
1539
|
|
1437
1540
|
wrapped = true
|
1438
1541
|
|
1439
|
-
(@lines.length - 1).downto(
|
1542
|
+
(@lines.length - 1).downto(from_row + 1) do |i|
|
1440
1543
|
if index = @lines[ i ].rindex( regexp )
|
1441
1544
|
match = Regexp.last_match
|
1442
1545
|
found_text = match[ 0 ]
|
@@ -1451,12 +1554,12 @@ class Buffer
|
|
1451
1554
|
|
1452
1555
|
# And finally, the other side of the current row.
|
1453
1556
|
|
1454
|
-
search_col = ( @last_finding ? @last_finding.start_col :
|
1455
|
-
if index = @lines[
|
1557
|
+
search_col = ( @last_finding ? @last_finding.start_col : from_col ) + 1
|
1558
|
+
if index = @lines[ from_row ].rindex( regexp )
|
1456
1559
|
if index > search_col
|
1457
1560
|
match = Regexp.last_match
|
1458
1561
|
found_text = match[ 0 ]
|
1459
|
-
finding = Finding.new(
|
1562
|
+
finding = Finding.new( from_row, index, from_row, index + found_text.length )
|
1460
1563
|
if finding.match( regexps, @lines )
|
1461
1564
|
throw :found
|
1462
1565
|
else
|
@@ -1468,7 +1571,9 @@ class Buffer
|
|
1468
1571
|
end
|
1469
1572
|
|
1470
1573
|
if finding
|
1471
|
-
|
1574
|
+
if wrapped and not options[ :quiet ]
|
1575
|
+
@diakonos.setILine( "(search wrapped around BOF/EOF)" )
|
1576
|
+
end
|
1472
1577
|
|
1473
1578
|
removeSelection( DONT_DISPLAY )
|
1474
1579
|
@last_finding = finding
|
@@ -1510,11 +1615,11 @@ class Buffer
|
|
1510
1615
|
case choice
|
1511
1616
|
when CHOICE_YES
|
1512
1617
|
paste [ actual_replacement ]
|
1513
|
-
find( regexps, direction, replacement )
|
1618
|
+
find( regexps, :direction => direction, :replacement => replacement )
|
1514
1619
|
when CHOICE_ALL
|
1515
1620
|
replaceAll( regexp, replacement )
|
1516
1621
|
when CHOICE_NO
|
1517
|
-
find( regexps, direction, replacement )
|
1622
|
+
find( regexps, :direction => direction, :replacement => replacement )
|
1518
1623
|
when CHOICE_CANCEL
|
1519
1624
|
# Do nothing further.
|
1520
1625
|
when CHOICE_YES_AND_STOP
|
@@ -1523,7 +1628,11 @@ class Buffer
|
|
1523
1628
|
end
|
1524
1629
|
end
|
1525
1630
|
else
|
1631
|
+
removeSelection DONT_DISPLAY
|
1632
|
+
clearMatches DO_DISPLAY
|
1633
|
+
if not options[ :quiet ]
|
1526
1634
|
@diakonos.setILine "/#{regexp.source}/ not found."
|
1635
|
+
end
|
1527
1636
|
end
|
1528
1637
|
end
|
1529
1638
|
|
@@ -1559,10 +1668,12 @@ class Buffer
|
|
1559
1668
|
end
|
1560
1669
|
|
1561
1670
|
def findAgain( last_search_regexps, direction = @last_search_direction )
|
1562
|
-
if @last_search_regexps
|
1563
|
-
|
1671
|
+
if @last_search_regexps.nil?
|
1672
|
+
@last_search_regexps = last_search_regexps
|
1673
|
+
end
|
1674
|
+
if @last_search_regexps
|
1675
|
+
find( @last_search_regexps, :direction => direction )
|
1564
1676
|
end
|
1565
|
-
find( @last_search_regexps, direction ) if( @last_search_regexps != nil )
|
1566
1677
|
end
|
1567
1678
|
|
1568
1679
|
def seek( regexp, direction = :down )
|
@@ -1717,38 +1828,70 @@ class Buffer
|
|
1717
1828
|
end
|
1718
1829
|
|
1719
1830
|
def undo
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1831
|
+
if @current_buffer_state < @buffer_states.length - 1
|
1832
|
+
@current_buffer_state += 1
|
1833
|
+
@lines = @buffer_states[ @current_buffer_state ]
|
1834
|
+
cursorTo( @cursor_states[ @current_buffer_state - 1 ][ 0 ], @cursor_states[ @current_buffer_state - 1 ][ 1 ] )
|
1835
|
+
@diakonos.setILine "Undo level: #{@current_buffer_state} of #{@buffer_states.length - 1}"
|
1836
|
+
setModified
|
1837
|
+
end
|
1727
1838
|
end
|
1728
1839
|
|
1729
1840
|
# Since redo is a Ruby keyword...
|
1730
1841
|
def unundo
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1842
|
+
if @current_buffer_state > 0
|
1843
|
+
@current_buffer_state += -1
|
1844
|
+
@lines = @buffer_states[ @current_buffer_state ]
|
1845
|
+
cursorTo( @cursor_states[ @current_buffer_state ][ 0 ], @cursor_states[ @current_buffer_state ][ 1 ] )
|
1846
|
+
@diakonos.setILine "Undo level: #{@current_buffer_state} of #{@buffer_states.length - 1}"
|
1847
|
+
setModified
|
1848
|
+
end
|
1849
|
+
end
|
1850
|
+
|
1851
|
+
def wrap_paragraph
|
1852
|
+
start_row = end_row = @last_row
|
1853
|
+
until start_row == 0 || @lines[ start_row - 1 ].strip == ''
|
1854
|
+
start_row -= 1
|
1855
|
+
end
|
1856
|
+
until end_row == @lines.size || @lines[ end_row ].strip == ''
|
1857
|
+
end_row += 1
|
1858
|
+
end
|
1859
|
+
|
1860
|
+
lines = []
|
1861
|
+
line = ''
|
1862
|
+
words = @lines[ start_row...end_row ].join( ' ' ).scan( /\S+/ )
|
1863
|
+
words.each do |word|
|
1864
|
+
if word =~ /^[a-z']+[.!?]$/
|
1865
|
+
word = "#{word} "
|
1866
|
+
end
|
1867
|
+
if line.length + word.length + 1 > ( @settings[ "lang.#{@language}.wrap_margin" ] || 80 )
|
1868
|
+
lines << line.strip
|
1869
|
+
line = ''
|
1737
1870
|
end
|
1871
|
+
line << " #{word}"
|
1872
|
+
end
|
1873
|
+
line.strip!
|
1874
|
+
if not line.empty?
|
1875
|
+
lines << line
|
1876
|
+
end
|
1877
|
+
if @lines[ start_row...end_row ] != lines
|
1878
|
+
@lines[ start_row...end_row ] = lines
|
1879
|
+
setModified
|
1880
|
+
end
|
1738
1881
|
end
|
1739
1882
|
|
1740
1883
|
def goToLine( line = nil, column = nil )
|
1741
|
-
|
1884
|
+
cursorTo( line || @last_row, column || 0, DO_DISPLAY )
|
1742
1885
|
end
|
1743
1886
|
|
1744
1887
|
def goToNextBookmark
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1888
|
+
cur_pos = Bookmark.new( self, @last_row, @last_col )
|
1889
|
+
next_bm = @bookmarks.find do |bm|
|
1890
|
+
bm > cur_pos
|
1891
|
+
end
|
1892
|
+
if next_bm
|
1893
|
+
cursorTo( next_bm.row, next_bm.col, DO_DISPLAY )
|
1894
|
+
end
|
1752
1895
|
end
|
1753
1896
|
|
1754
1897
|
def goToPreviousBookmark
|
data/lib/diakonos/readline.rb
CHANGED
@@ -1,219 +1,255 @@
|
|
1
1
|
module Diakonos
|
2
|
-
|
3
|
-
class Readline
|
4
|
-
|
2
|
+
|
3
|
+
class Readline
|
4
|
+
|
5
5
|
# completion_array is the array of strings that tab completion can use
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
# The block returns true if a refresh is needed?
|
7
|
+
def initialize( diakonos, window, prompt, initial_text = "", completion_array = nil, history = [], &block )
|
8
|
+
@diakonos = diakonos
|
9
|
+
@window = window
|
10
|
+
@prompt = prompt
|
11
|
+
pos = redraw_prompt
|
12
|
+
@window.setpos( 0, pos )
|
13
|
+
@initial_text = initial_text
|
14
|
+
@completion_array = completion_array
|
15
|
+
@list_filename = @diakonos.list_filename
|
16
|
+
|
17
|
+
@history = history
|
18
|
+
@history << initial_text
|
19
|
+
@history_index = @history.length - 1
|
20
|
+
|
21
|
+
@block = block
|
16
22
|
end
|
17
|
-
|
23
|
+
|
24
|
+
def redraw_prompt
|
25
|
+
@diakonos.setILine @prompt
|
26
|
+
end
|
27
|
+
|
28
|
+
def call_block
|
29
|
+
if @block
|
30
|
+
@block.call( @input )
|
31
|
+
@window.refresh
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
18
35
|
# Returns nil on cancel.
|
19
36
|
def readline
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
37
|
+
@input = @initial_text
|
38
|
+
if not @input.empty?
|
39
|
+
call_block
|
40
|
+
end
|
41
|
+
|
42
|
+
@icurx = @window.curx
|
43
|
+
@icury = @window.cury
|
44
|
+
@window.addstr @initial_text
|
45
|
+
@input_cursor = @initial_text.length
|
46
|
+
@opened_list_file = false
|
47
|
+
|
48
|
+
loop do
|
49
|
+
c = @window.getch
|
50
|
+
|
51
|
+
case c
|
52
|
+
when Curses::KEY_DC
|
53
|
+
if @input_cursor < @input.length
|
54
|
+
@window.delch
|
55
|
+
@input = @input[ 0...@input_cursor ] + @input[ (@input_cursor + 1)..-1 ]
|
56
|
+
call_block
|
57
|
+
end
|
58
|
+
when BACKSPACE, CTRL_H
|
59
|
+
# Curses::KEY_LEFT
|
60
|
+
if @input_cursor > 0
|
61
|
+
@input_cursor += -1
|
62
|
+
@window.setpos( @window.cury, @window.curx - 1 )
|
63
|
+
|
64
|
+
# Curses::KEY_DC
|
65
|
+
if @input_cursor < @input.length
|
66
|
+
@window.delch
|
67
|
+
@input = @input[ 0...@input_cursor ] + @input[ (@input_cursor + 1)..-1 ]
|
68
|
+
call_block
|
69
|
+
end
|
70
|
+
end
|
71
|
+
when ENTER, Curses::KEY_F3
|
72
|
+
item = @diakonos.current_list_item
|
73
|
+
if item and File.directory? item
|
74
|
+
completeInput
|
75
|
+
else
|
76
|
+
break
|
77
|
+
end
|
78
|
+
when ESCAPE, CTRL_C, CTRL_D, CTRL_Q
|
79
|
+
@input = nil
|
80
|
+
break
|
81
|
+
when Curses::KEY_LEFT
|
82
|
+
if @input_cursor > 0
|
83
|
+
@input_cursor += -1
|
84
|
+
@window.setpos( @window.cury, @window.curx - 1 )
|
85
|
+
end
|
86
|
+
when Curses::KEY_RIGHT
|
87
|
+
if @input_cursor < @input.length
|
88
|
+
@input_cursor += 1
|
89
|
+
@window.setpos( @window.cury, @window.curx + 1 )
|
90
|
+
end
|
91
|
+
when Curses::KEY_HOME
|
92
|
+
@input_cursor = 0
|
93
|
+
@window.setpos( @icury, @icurx )
|
94
|
+
when Curses::KEY_END
|
95
|
+
@input_cursor = @input.length
|
96
|
+
@window.setpos( @window.cury, @icurx + @input.length )
|
97
|
+
when TAB
|
98
|
+
completeInput
|
99
|
+
when Curses::KEY_NPAGE
|
100
|
+
@diakonos.pageDown
|
101
|
+
line = @diakonos.select_list_item
|
102
|
+
if line
|
103
|
+
@input = line
|
104
|
+
cursorWriteInput
|
105
|
+
end
|
106
|
+
when Curses::KEY_PPAGE
|
107
|
+
@diakonos.pageUp
|
108
|
+
line = @diakonos.select_list_item
|
109
|
+
if line
|
110
|
+
@input = line
|
111
|
+
cursorWriteInput
|
112
|
+
end
|
113
|
+
when Curses::KEY_UP
|
114
|
+
if @diakonos.showing_list?
|
115
|
+
if @diakonos.list_item_selected?
|
116
|
+
@diakonos.previous_list_item
|
117
|
+
end
|
118
|
+
@input = @diakonos.select_list_item
|
119
|
+
elsif @history_index > 0
|
120
|
+
@history[ @history_index ] = @input
|
121
|
+
@history_index -= 1
|
122
|
+
@input = @history[ @history_index ]
|
123
|
+
end
|
124
|
+
cursorWriteInput
|
125
|
+
when Curses::KEY_DOWN
|
126
|
+
if @diakonos.showing_list?
|
127
|
+
if @diakonos.list_item_selected?
|
128
|
+
@diakonos.next_list_item
|
129
|
+
end
|
130
|
+
@input = @diakonos.select_list_item
|
131
|
+
elsif @history_index < @history.length - 1
|
132
|
+
@history[ @history_index ] = @input
|
133
|
+
@history_index += 1
|
134
|
+
@input = @history[ @history_index ]
|
135
|
+
end
|
136
|
+
cursorWriteInput
|
137
|
+
when CTRL_K
|
138
|
+
@input = ""
|
139
|
+
if @block
|
140
|
+
@block.call @input
|
141
|
+
end
|
142
|
+
cursorWriteInput
|
143
|
+
else
|
144
|
+
if c > 31 and c < 255 and c != BACKSPACE
|
145
|
+
if @input_cursor == @input.length
|
146
|
+
@input << c
|
147
|
+
@window.addch c
|
148
|
+
else
|
149
|
+
@input = @input[ 0...@input_cursor ] + c.chr + @input[ @input_cursor..-1 ]
|
150
|
+
@window.setpos( @window.cury, @window.curx + 1 )
|
151
|
+
redrawInput
|
127
152
|
end
|
153
|
+
@input_cursor += 1
|
154
|
+
call_block
|
155
|
+
else
|
156
|
+
@diakonos.log "Other input: #{c}"
|
157
|
+
end
|
128
158
|
end
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
return @input
|
159
|
+
end
|
160
|
+
|
161
|
+
@diakonos.closeListBuffer
|
162
|
+
|
163
|
+
@history[ -1 ] = @input
|
135
164
|
end
|
136
165
|
|
137
166
|
def redrawInput
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
167
|
+
input = @input[ 0...Curses::cols ]
|
168
|
+
|
169
|
+
curx = @window.curx
|
170
|
+
cury = @window.cury
|
171
|
+
@window.setpos( @icury, @icurx )
|
172
|
+
@window.addstr "%-#{ Curses::cols - curx }s%s" % [ input, " " * ( Curses::cols - input.length ) ]
|
173
|
+
@window.setpos( cury, curx )
|
174
|
+
@window.refresh
|
144
175
|
end
|
145
|
-
|
176
|
+
|
146
177
|
# Redisplays the input text starting at the start of the user input area,
|
147
178
|
# positioning the cursor at the end of the text.
|
148
179
|
def cursorWriteInput
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
180
|
+
if @input != nil
|
181
|
+
@input_cursor = @input.length
|
182
|
+
@window.setpos( @window.cury, @icurx + @input.length )
|
183
|
+
redrawInput
|
184
|
+
end
|
154
185
|
end
|
155
186
|
|
156
187
|
def completeInput
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
188
|
+
if @completion_array and @input.length > 0
|
189
|
+
len = @input.length
|
190
|
+
matches = @completion_array.find_all { |el| el[ 0...len ] == @input and len <= el.length }
|
191
|
+
else
|
192
|
+
matches = Dir.glob( ( @input.subHome() + "*" ).gsub( /\*\*/, "*" ) )
|
193
|
+
end
|
194
|
+
|
195
|
+
if matches.length == 1
|
196
|
+
@input = matches[ 0 ]
|
197
|
+
cursorWriteInput
|
198
|
+
File.open( @list_filename, "w" ) do |f|
|
199
|
+
if @completion_array.nil?
|
200
|
+
f.puts "(unique)"
|
201
|
+
else
|
202
|
+
f.puts @input
|
203
|
+
end
|
162
204
|
end
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
205
|
+
if @completion_array.nil? and FileTest.directory?( @input )
|
206
|
+
@input << "/"
|
207
|
+
cursorWriteInput
|
208
|
+
completeInput
|
209
|
+
end
|
210
|
+
elsif matches.length > 1
|
211
|
+
common = matches[ 0 ]
|
212
|
+
File.open( @list_filename, "w" ) do |f|
|
213
|
+
i = nil
|
214
|
+
matches.each do |match|
|
215
|
+
f.print match
|
216
|
+
if FileTest.directory?( match )
|
217
|
+
f.print '/'
|
218
|
+
else
|
219
|
+
@diakonos.log "'#{match}' is not a directory"
|
174
220
|
end
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
f.print match
|
181
|
-
if FileTest.directory?( match )
|
182
|
-
f.print '/'
|
183
|
-
else
|
184
|
-
@diakonos.log "'#{match}' is not a directory"
|
185
|
-
end
|
186
|
-
f.puts
|
187
|
-
|
188
|
-
if match[ 0 ] != common[ 0 ]
|
189
|
-
common = nil
|
190
|
-
break
|
191
|
-
end
|
192
|
-
|
193
|
-
up_to = [ common.length - 1, match.length - 1 ].min
|
194
|
-
i = 1
|
195
|
-
while ( i <= up_to ) and ( match[ 0..i ] == common[ 0..i ] )
|
196
|
-
i += 1
|
197
|
-
end
|
198
|
-
common = common[ 0...i ]
|
199
|
-
end
|
221
|
+
f.puts
|
222
|
+
|
223
|
+
if match[ 0 ] != common[ 0 ]
|
224
|
+
common = nil
|
225
|
+
break
|
200
226
|
end
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
@input = common
|
207
|
-
cursorWriteInput
|
227
|
+
|
228
|
+
up_to = [ common.length - 1, match.length - 1 ].min
|
229
|
+
i = 1
|
230
|
+
while ( i <= up_to ) and ( match[ 0..i ] == common[ 0..i ] )
|
231
|
+
i += 1
|
208
232
|
end
|
233
|
+
common = common[ 0...i ]
|
234
|
+
end
|
235
|
+
end
|
236
|
+
if common == nil
|
237
|
+
File.open( @list_filename, "w" ) do |f|
|
238
|
+
f.puts "(no matches)"
|
239
|
+
end
|
209
240
|
else
|
210
|
-
|
211
|
-
|
212
|
-
|
241
|
+
@input = common
|
242
|
+
cursorWriteInput
|
243
|
+
end
|
244
|
+
else
|
245
|
+
File.open( @list_filename, "w" ) do |f|
|
246
|
+
f.puts "(no matches)"
|
213
247
|
end
|
214
|
-
|
215
|
-
|
248
|
+
end
|
249
|
+
@diakonos.openListBuffer
|
250
|
+
@window.setpos( @window.cury, @window.curx )
|
216
251
|
end
|
217
|
-
|
252
|
+
|
253
|
+
end
|
218
254
|
|
219
255
|
end
|