File tree Expand file tree Collapse file tree 3 files changed +43
-5
lines changed Expand file tree Collapse file tree 3 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ html_to_markdown = "0.1.0"
65
65
rust-embed = " 8.5.0"
66
66
os_info = { version = " 3.8.2" , default-features = false }
67
67
bm25 = { version = " 2.0.1" , features = [" parallelism" ] }
68
+ which = " 7.0.1"
68
69
69
70
[dependencies .reqwest ]
70
71
version = " 0.12.0"
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ use std::{
35
35
io:: Write ,
36
36
path:: { Path , PathBuf } ,
37
37
process,
38
- sync:: Arc ,
38
+ sync:: { Arc , OnceLock } ,
39
39
} ;
40
40
use syntect:: highlighting:: ThemeSet ;
41
41
@@ -88,6 +88,8 @@ __INPUT__
88
88
const LEFT_PROMPT : & str = "{color.green}{?session {?agent {agent}>}{session}{?role /}}{!session {?agent {agent}>}}{role}{?rag @{rag}}{color.cyan}{?session )}{!session >}{color.reset} " ;
89
89
const RIGHT_PROMPT : & str = "{color.purple}{?session {?consume_tokens {consume_tokens}({consume_percent}%)}{!consume_tokens {consume_tokens}}}{color.reset}" ;
90
90
91
+ static EDITOR : OnceLock < Option < String > > = OnceLock :: new ( ) ;
92
+
91
93
#[ derive( Debug , Clone , Deserialize ) ]
92
94
#[ serde( default ) ]
93
95
pub struct Config {
@@ -1640,10 +1642,20 @@ impl Config {
1640
1642
}
1641
1643
1642
1644
pub fn editor ( & self ) -> Result < String > {
1643
- self . editor
1644
- . clone ( )
1645
- . or_else ( || env:: var ( "VISUAL" ) . ok ( ) . or_else ( || env:: var ( "EDITOR" ) . ok ( ) ) )
1646
- . ok_or_else ( || anyhow ! ( "No editor, please configure `editor` or set $EDITOR/$VISUAL environment variable." ) )
1645
+ EDITOR . get_or_init ( move || {
1646
+ let editor = self . editor . clone ( )
1647
+ . or_else ( || env:: var ( "VISUAL" ) . ok ( ) . or_else ( || env:: var ( "EDITOR" ) . ok ( ) ) )
1648
+ . unwrap_or_else ( || {
1649
+ if cfg ! ( windows) {
1650
+ "notepad" . to_string ( )
1651
+ } else {
1652
+ "nano" . to_string ( )
1653
+ }
1654
+ } ) ;
1655
+ which:: which ( & editor) . ok ( ) . map ( |_| editor)
1656
+ } )
1657
+ . clone ( )
1658
+ . ok_or_else ( || anyhow ! ( "Editor not found. Please add the `editor` configuration or set the $EDITOR or $VISUAL environment variable." ) )
1647
1659
}
1648
1660
1649
1661
pub fn repl_complete (
You can’t perform that action at this time.
0 commit comments