Skip to content

Commit 643461a

Browse files
committed
Re-use the serial monitor Terminal window
* ArduinoSerialMonitor no longer deploys the code, it simply launches the serial monitor. This allows you to launch the monitor after deploying without re-deploying. It also fixes a recursion bug if you have auto_open_serial set. * The screen session is named. This allows us to kill the session before each deploy, allowing you to deploy without manually stopping the serial monitor * The AppleScript uses the native Terminal application, removing the iTerm dependency. * The AppleScript uses the same Terminal window for serial monitoring. If a serial monitor tab doesn't exist it creates one. Basically, this commit allows you to open the serial monitor at will, and decouples serial monitor management from deployment. You can <leader>ad at will and the monitor will always be up to date.
1 parent 4d94c67 commit 643461a

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

plugin/vim-arduino-serial

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,37 @@ echo "use Ctrl-a, k to exit the screen utility"
55
port=$(ls /dev/tty.* | grep usb)
66

77
osascript -e \
8-
"tell application \"iTerm\"
9-
activate
10-
set myterm to (current terminal)
11-
tell myterm
12-
set mysession to (make new session at the end of sessions)
13-
tell mysession
14-
exec command \"/bin/bash -l\"
15-
write text \"screen $port\"
16-
end tell
8+
"tell application \"Terminal\"
9+
activate
10+
11+
-- search all windows for the arduino-serial tab
12+
set winlist to every window
13+
local arduinoTab
14+
repeat with win in winlist
15+
set tablist to every tab of win
16+
repeat with currentTab in tablist
17+
set title to get custom title of currentTab
18+
if title is equal to \"arduino-serial\" then
19+
set arduinoTab to currentTab
20+
set frontmost of win to true
21+
end if
22+
end repeat
23+
end repeat
24+
25+
-- make new tab when arduino-serial does not exist
26+
try
27+
arduinoTab
28+
on error
29+
tell application \"System Events\"
30+
set frontmost of application process \"Terminal\" to true
31+
keystroke \"t\" using command down
1732
end tell
18-
end tell"
33+
set currentTabIndex to (get count of tabs of front window)
34+
set arduinoTab to (tab currentTabIndex of front window)
35+
set custom title of arduinoTab to \"arduino-serial\"
36+
end try
37+
38+
tell front window
39+
do script \"screen -S arduino-serial $port\" in arduinoTab
40+
end tell
41+
end tell"

plugin/vim-arduino.vim

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ endfunction
2424
"
2525
" Returns nothing.
2626
function! s:InvokeArduinoCli(deploy)
27+
call s:ArduinoKillMonitor()
2728
let l:flag = a:deploy ? "-d" : "-c"
2829
let l:f_name = expand('%:p')
2930
execute "w"
@@ -41,6 +42,13 @@ function! s:InvokeArduinoCli(deploy)
4142
return !v:shell_error
4243
endfunction
4344

45+
" Private: Release the /dev/tty.usb* port so we can recompile
46+
"
47+
" Returns nothing.
48+
function! s:ArduinoKillMonitor()
49+
let output = system("screen -X -S arduino-serial quit")
50+
endfunction
51+
4452
" Public: Compile the current pde file.
4553
"
4654
" Returns nothing.
@@ -64,9 +72,8 @@ endfunction
6472
"
6573
" Returns nothing.
6674
function! ArduinoSerialMonitor()
67-
if ArduinoDeploy()
68-
echo system(s:helper_dir."/vim-arduino-serial")
69-
endif
75+
call s:ArduinoKillMonitor()
76+
echo system(s:helper_dir."/vim-arduino-serial")
7077
endfunction
7178

7279
if !exists('g:vim_arduino_map_keys')

0 commit comments

Comments
 (0)