5
5
6
6
use super :: common:: * ;
7
7
use std:: { fs, thread:: sleep, time:: Duration } ;
8
- use tempfile:: TempDir ;
9
8
10
9
// ANSI escape sequences for function keys
11
10
const F8_KEY : & str = "\x1b [19~" ;
12
11
const F9_KEY : & str = "\x1b [20~" ;
13
12
13
+ /// Helper to create a custom cable directory with external actions.
14
+ fn write_toml_config (
15
+ cable_dir : & std:: path:: Path ,
16
+ filename : & str ,
17
+ content : & str ,
18
+ ) {
19
+ let toml_path = cable_dir. join ( filename) ;
20
+ fs:: write ( & toml_path, content) . unwrap ( ) ;
21
+ }
22
+
14
23
/// Tests that external actions execute properly when triggered by keybindings.
15
24
#[ test]
16
25
fn test_external_action_lsman_with_f9 ( ) {
17
26
let mut tester = PtyTester :: new ( ) ;
18
27
19
- // Create a temporary directory for the custom cable
20
- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
21
- let cable_dir = temp_dir . path ( ) ;
28
+ // Use TARGET_DIR for consistency with other tests
29
+ let cable_dir = std :: path :: Path :: new ( TARGET_DIR ) . join ( "custom_cable" ) ;
30
+ fs :: create_dir_all ( & cable_dir) . unwrap ( ) ;
22
31
23
32
// Create a custom files.toml with external actions
24
33
let files_toml_content = r#"
@@ -40,17 +49,15 @@ f8 = "thebatman"
40
49
f9 = "lsman"
41
50
42
51
[actions.thebatman]
43
- description = "cats the file"
44
- command = "bat '{}'"
45
- env = { BAT_THEME = "ansi" }
52
+ description = "show file content"
53
+ command = "cat '{}'"
46
54
47
55
[actions.lsman]
48
56
description = "show stats"
49
57
command = "ls '{}'"
50
58
"# ;
51
59
52
- let files_toml_path = cable_dir. join ( "files.toml" ) ;
53
- fs:: write ( & files_toml_path, files_toml_content) . unwrap ( ) ;
60
+ write_toml_config ( & cable_dir, "files.toml" , files_toml_content) ;
54
61
55
62
// Use the LICENSE file as input since it exists in the repo
56
63
let mut cmd = tv ( ) ;
@@ -82,9 +89,8 @@ command = "ls '{}'"
82
89
fn test_external_action_thebatman_with_f8 ( ) {
83
90
let mut tester = PtyTester :: new ( ) ;
84
91
85
- // Create a temporary directory for the custom cable
86
- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
87
- let cable_dir = temp_dir. path ( ) ;
92
+ let cable_dir = std:: path:: Path :: new ( TARGET_DIR ) . join ( "custom_cable_f8" ) ;
93
+ fs:: create_dir_all ( & cable_dir) . unwrap ( ) ;
88
94
89
95
// Create a custom files.toml with external actions
90
96
let files_toml_content = r#"
@@ -106,17 +112,15 @@ f8 = "thebatman"
106
112
f9 = "lsman"
107
113
108
114
[actions.thebatman]
109
- description = "cats the file"
110
- command = "bat '{}'"
111
- env = { BAT_THEME = "ansi" }
115
+ description = "show file content"
116
+ command = "cat '{}'"
112
117
113
118
[actions.lsman]
114
119
description = "show stats"
115
120
command = "ls '{}'"
116
121
"# ;
117
122
118
- let files_toml_path = cable_dir. join ( "files.toml" ) ;
119
- fs:: write ( & files_toml_path, files_toml_content) . unwrap ( ) ;
123
+ write_toml_config ( & cable_dir, "files.toml" , files_toml_content) ;
120
124
121
125
// Use the LICENSE file as input since it exists in the repo
122
126
let mut cmd = tv ( ) ;
@@ -129,7 +133,7 @@ command = "ls '{}'"
129
133
// Wait for the UI to load
130
134
sleep ( DEFAULT_DELAY ) ;
131
135
132
- // Send F8 to trigger the "thebatman" action (mapped to bat command)
136
+ // Send F8 to trigger the "thebatman" action (mapped to cat command)
133
137
tester. send ( F8_KEY ) ;
134
138
135
139
// Give time for the action to execute
0 commit comments