@@ -17,43 +17,43 @@ extern mod linenoise {
17
17
18
18
/// Add a line to history
19
19
pub fn add_history ( line : ~str ) -> bool {
20
- do str:: as_c_str ( line) |buf| {
21
- linenoise:: linenoiseHistoryAdd ( buf) == 1 as c_int
22
- }
20
+ do str:: as_c_str ( line) |buf| {
21
+ linenoise:: linenoiseHistoryAdd ( buf) == 1 as c_int
22
+ }
23
23
}
24
24
25
25
/// Set the maximum amount of lines stored
26
26
pub fn set_history_max_len ( len : int ) -> bool {
27
- linenoise:: linenoiseHistorySetMaxLen ( len as c_int ) == 1 as c_int
27
+ linenoise:: linenoiseHistorySetMaxLen ( len as c_int ) == 1 as c_int
28
28
}
29
29
30
30
/// Save line history to a file
31
31
pub fn save_history ( file : ~str ) -> bool {
32
- do str:: as_c_str ( file) |buf| {
33
- linenoise:: linenoiseHistorySave ( buf) == 1 as c_int
34
- }
32
+ do str:: as_c_str ( file) |buf| {
33
+ linenoise:: linenoiseHistorySave ( buf) == 1 as c_int
34
+ }
35
35
}
36
36
37
37
/// Load line history from a file
38
38
pub fn load_history ( file : ~str ) -> bool {
39
- do str:: as_c_str ( file) |buf| {
40
- linenoise:: linenoiseHistoryLoad ( buf) == 1 as c_int
41
- }
39
+ do str:: as_c_str ( file) |buf| {
40
+ linenoise:: linenoiseHistoryLoad ( buf) == 1 as c_int
41
+ }
42
42
}
43
43
44
44
/// Print out a prompt and then wait for input and return it
45
45
pub fn read ( prompt : ~str ) -> Option < ~str > {
46
- do str:: as_c_str ( prompt) |buf| unsafe {
47
- let line = linenoise:: linenoise ( buf) ;
46
+ do str:: as_c_str ( prompt) |buf| unsafe {
47
+ let line = linenoise:: linenoise ( buf) ;
48
48
49
- if line. is_null ( ) { None }
50
- else { Some ( str:: raw:: from_c_str ( line) ) }
51
- }
49
+ if line. is_null ( ) { None }
50
+ else { Some ( str:: raw:: from_c_str ( line) ) }
51
+ }
52
52
}
53
53
54
54
/// Clear the screen
55
55
pub fn clear ( ) {
56
- linenoise:: linenoiseClearScreen ( ) ;
56
+ linenoise:: linenoiseClearScreen ( ) ;
57
57
}
58
58
59
59
pub type CompletionCb = fn ~( ~str , fn ( ~str ) ) ;
@@ -62,17 +62,17 @@ fn complete_key(_v: @CompletionCb) {}
62
62
63
63
/// Bind to the main completion callback
64
64
pub fn complete ( cb : CompletionCb ) unsafe {
65
- task:: local_data:: local_data_set ( complete_key, @( move cb) ) ;
65
+ task:: local_data:: local_data_set ( complete_key, @( move cb) ) ;
66
66
67
- extern fn callback ( line : * c_char , completions : * ( ) ) unsafe {
68
- let cb: CompletionCb = copy * task:: local_data:: local_data_get ( complete_key) . get ( ) ;
67
+ extern fn callback ( line : * c_char , completions : * ( ) ) unsafe {
68
+ let cb = copy * task:: local_data:: local_data_get ( complete_key) . get ( ) ;
69
69
70
- do cb( str:: raw:: from_c_str ( line) ) |suggestion| {
71
- do str:: as_c_str ( suggestion) |buf| {
72
- linenoise:: linenoiseAddCompletion ( completions, buf) ;
73
- }
74
- }
75
- }
70
+ do cb( str:: raw:: from_c_str ( line) ) |suggestion| {
71
+ do str:: as_c_str ( suggestion) |buf| {
72
+ linenoise:: linenoiseAddCompletion ( completions, buf) ;
73
+ }
74
+ }
75
+ }
76
76
77
- linenoise:: linenoiseSetCompletionCallback ( callback) ;
77
+ linenoise:: linenoiseSetCompletionCallback ( callback) ;
78
78
}
0 commit comments