2
2
--- Launches Claude Code in an external terminal application using a user-specified command.
3
3
--- @module ' claudecode.terminal.external'
4
4
5
- --- @type TerminalProvider
5
+ --- @type ClaudeCodeTerminalProvider
6
6
local M = {}
7
7
8
8
local logger = require (" claudecode.logger" )
9
9
local utils = require (" claudecode.utils" )
10
10
11
11
local jobid = nil
12
- --- @type TerminalConfig
12
+ --- @type ClaudeCodeTerminalConfig
13
13
local config
14
14
15
15
local function cleanup_state ()
@@ -22,15 +22,15 @@ local function is_valid()
22
22
return jobid and jobid > 0
23
23
end
24
24
25
- --- @param term_config TerminalConfig
25
+ --- @param term_config ClaudeCodeTerminalConfig
26
26
function M .setup (term_config )
27
27
config = term_config or {}
28
28
end
29
29
30
- --- @param cmd_string string
31
- --- @param env_table table
32
- --- @param effective_config table
33
- --- @param focus boolean | nil
30
+ --- @param cmd_string string
31
+ --- @param env_table table
32
+ --- @param effective_config table
33
+ --- @param focus boolean ?
34
34
function M .open (cmd_string , env_table , effective_config , focus )
35
35
focus = utils .normalize_focus (focus )
36
36
@@ -54,10 +54,7 @@ function M.open(cmd_string, env_table, effective_config, focus)
54
54
55
55
-- Replace %s in the template with the Claude command
56
56
if not external_cmd :find (" %%s" ) then
57
- vim .notify (
58
- " external_terminal_cmd must contain '%s' placeholder for the Claude command." ,
59
- vim .log .levels .ERROR
60
- )
57
+ vim .notify (" external_terminal_cmd must contain '%s' placeholder for the Claude command." , vim .log .levels .ERROR )
61
58
return
62
59
end
63
60
@@ -94,9 +91,9 @@ function M.close()
94
91
end
95
92
96
93
--- Simple toggle: always start external terminal (can't hide external terminals)
97
- --- @param cmd_string string
98
- --- @param env_table table
99
- --- @param effective_config table
94
+ --- @param cmd_string string
95
+ --- @param env_table table
96
+ --- @param effective_config table
100
97
function M .simple_toggle (cmd_string , env_table , effective_config )
101
98
if is_valid () then
102
99
-- External terminal is running, stop it
@@ -108,42 +105,39 @@ function M.simple_toggle(cmd_string, env_table, effective_config)
108
105
end
109
106
110
107
--- Smart focus toggle: same as simple toggle for external terminals
111
- --- @param cmd_string string
112
- --- @param env_table table
113
- --- @param effective_config table
108
+ --- @param cmd_string string
109
+ --- @param env_table table
110
+ --- @param effective_config table
114
111
function M .focus_toggle (cmd_string , env_table , effective_config )
115
112
-- For external terminals, focus toggle behaves the same as simple toggle
116
113
-- since we can't detect or control focus of external windows
117
114
M .simple_toggle (cmd_string , env_table , effective_config )
118
115
end
119
116
120
117
--- Legacy toggle function for backward compatibility
121
- --- @param cmd_string string
122
- --- @param env_table table
123
- --- @param effective_config table
118
+ --- @param cmd_string string
119
+ --- @param env_table table
120
+ --- @param effective_config table
124
121
function M .toggle (cmd_string , env_table , effective_config )
125
122
M .simple_toggle (cmd_string , env_table , effective_config )
126
123
end
127
124
128
- --- @return number | nil
125
+ --- @return number ?
129
126
function M .get_active_bufnr ()
130
127
-- External terminals don't have associated Neovim buffers
131
128
return nil
132
129
end
133
130
134
131
--- No-op function for external terminals since we can't ensure visibility of external windows
135
- function M .ensure_visible ()
136
- -- For external terminals, we can't control window visibility
137
- -- This is a no-op to prevent unnecessary buffer searches
138
- end
132
+ function M .ensure_visible () end
139
133
140
- --- @return boolean
134
+ --- @return boolean
141
135
function M .is_available ()
142
136
-- Availability is checked by terminal.lua before this provider is selected
143
137
return true
144
138
end
145
139
146
- --- @return table | nil
140
+ --- @return table ?
147
141
function M ._get_terminal_for_test ()
148
142
-- For testing purposes, return job info if available
149
143
if is_valid () then
0 commit comments