Skip to content

Commit e76ccf9

Browse files
committed
Add better mac compatibility
1 parent d8506d2 commit e76ccf9

File tree

6 files changed

+76
-48
lines changed

6 files changed

+76
-48
lines changed

Diff for: README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,25 @@ following:
4848

4949
```vim
5050
" my_file.ino [arduino:avr:uno]
51-
function! b:MyStatusLine()
51+
function! MyStatusLine()
5252
return '%f [' . g:arduino_board . ']'
5353
endfunction
54-
setl statusline=%!b:MyStatusLine()
54+
setl statusline=%!MyStatusLine()
5555
```
5656

5757
Or if you want something a bit fancier that includes serial port info:
5858

5959
```vim
6060
" my_file.ino [arduino:avr:uno] [arduino:usbtinyisp] (/dev/ttyACM0:9600)
61-
function! b:MyStatusLine()
61+
function! MyStatusLine()
6262
let port = arduino#GetPort()
6363
let line = '%f [' . g:arduino_board . '] [' . g:arduino_programmer . ']'
6464
if !empty(port)
6565
let line = line . ' (' . port . ':' . g:arduino_serial_baud . ')'
6666
endif
6767
return line
6868
endfunction
69-
setl statusline=%!b:MyStatusLine()
69+
setl statusline=%!MyStatusLine()
7070
```
7171

7272

Diff for: autoload/arduino.vim

+28-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ if (exists('g:loaded_arduino_autoload') && g:loaded_arduino_autoload)
22
finish
33
endif
44
let g:loaded_arduino_autoload = 1
5+
if has('win64') || has('win32') || has('win16')
6+
echo "vim-arduino does not support windows :("
7+
finish
8+
endif
59
let s:HERE = resolve(expand('<sfile>:p:h:h'))
10+
let s:OS = substitute(system('uname'), '\n', '', '')
611
" In neovim, run the shell commands using :terminal to preserve interactivity
712
if has('nvim')
813
let s:TERM = 'terminal! '
@@ -42,6 +47,10 @@ function! arduino#InitializeConfig()
4247
if !exists('g:arduino_serial_tmux')
4348
let g:arduino_serial_tmux = 'split-window -d'
4449
endif
50+
if !exists('g:arduino_run_headless')
51+
let xvfbPath = substitute(system('command -v Xvfb'), "\n*$", '', '')
52+
let g:arduino_run_headless = empty(xvfbPath) ? 0 : 1
53+
endif
4554

4655
if !exists('g:arduino_serial_port_globs')
4756
let g:arduino_serial_port_globs = ['/dev/ttyACM*',
@@ -73,12 +82,23 @@ function! arduino#SaveCache()
7382
endfunction
7483

7584
" Arduino command helpers {{{1
76-
function! arduino#GetArduinoCommand(cmd)
85+
function! arduino#GetArduinoExecutable()
7786
if exists('g:arduino_cmd')
78-
let arduino = g:arduino_cmd
87+
return g:arduino_cmd
88+
elseif s:OS == 'Darwin'
89+
return '/Applications/Arduino.app/Contents/MacOS/Arduino'
7990
else
80-
let arduino = s:HERE . '/bin/arduino-headless'
91+
return 'arduino'
92+
endif
93+
endfunction
94+
95+
function! arduino#GetArduinoCommand(cmd)
96+
let arduino = arduino#GetArduinoExecutable()
97+
98+
if g:arduino_run_headless
99+
let arduino = s:HERE . '/bin/run-headless ' . arduino
81100
endif
101+
82102
let cmd = arduino . ' ' . a:cmd . " --board " . g:arduino_board
83103
let port = arduino#GetPort()
84104
if !empty(port)
@@ -400,8 +420,12 @@ function! arduino#GetArduinoDir()
400420
if exists('g:arduino_dir')
401421
return g:arduino_dir
402422
endif
403-
let arduino_cmd = arduino#FindExecutable('arduino')
423+
let executable = arduino#GetArduinoExecutable()
424+
let arduino_cmd = arduino#FindExecutable(executable)
404425
let arduino_dir = fnamemodify(arduino_cmd, ':h')
426+
if s:OS == 'Darwin'
427+
let arduino_dir = fnamemodify(arduino_dir, ':h') . '/Java'
428+
endif
405429
if !s:FileExists(arduino_dir . '/hardware/arduino/')
406430
throw "Could not find arduino directory. Please set g:arduino_dir"
407431
endif

Diff for: bin/arduino-headless

-35
This file was deleted.

Diff for: bin/run-headless

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash -e
2+
# Wrapper script that will automatically use Xvfb to run a command
3+
declare -r XVFB="Xvfb :1 -nolisten tcp -screen :1 1280x800x24"
4+
5+
cleanup() {
6+
if [[ -n "$xvfb_proc" ]] && kill -0 $xvfb_proc; then
7+
kill -9 $xvfb_proc
8+
fi
9+
}
10+
11+
main() {
12+
# If we're using --verbose or --verbose-build, show the output of xvfb
13+
local silent=1
14+
for arg in $@; do
15+
if [[ "$arg" == "--verbose" ]] || [[ "$arg" == "--verbose-build" ]]; then
16+
silent=
17+
break
18+
fi
19+
done
20+
if [ $silent ]; then
21+
$XVFB > /dev/null 2> /dev/null &
22+
else
23+
$XVFB &
24+
fi
25+
xvfb_proc="$!"
26+
trap cleanup SIGINT SIGTERM EXIT
27+
DISPLAY=:1 "$@"
28+
}
29+
30+
main "$@"

Diff for: doc/arduino.txt

+13-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ OPTIONS *arduino-options*
2323

2424
Overview:~
2525

26-
|arduino_board|................The fully-qualified name of the board.
26+
|arduino_cmd|..................Path to the arduino executable
27+
|arduino_dir|..................Path to the arduino install directory
28+
|arduino_run_headless|.........Try to run inside Xvfb
2729
|arduino_args|.................Additional args to pass to 'arduino' command.
30+
|arduino_board|................The fully-qualified name of the board.
31+
|arduino_programmer|...........The programmer type.
2832
|arduino_serial_cmd|...........Command to run to attach to serial port.
2933
|arduino_serial_baud|..........The baud rate for the serial connection.
3034
|arduino_auto_baud|............Auto-detect the baud rate.
@@ -36,15 +40,19 @@ Overview:~
3640
Detailed descriptions and default values:~
3741

3842
*'g:arduino_cmd'*
39-
The path to the 'arduino' command. By default it will use the
40-
'arduino-headless' script in the 'bin' directory, which looks for 'arduino' in
41-
your PATH and runs it inside Xvfb if it can. >
43+
The path to the 'arduino' command. By default it will look in your PATH, or in
44+
Applications on Mac. >
4245
let g:arduino_cmd = '/usr/share/local/arduino/arduino'
4346
<
4447
*'g:arduino_dir'*
4548
The path to your 'arduino' directory. Usually vim-arduino will be able to
46-
detect it, but if it cannot you can set the value manually.
49+
detect it, but if it cannot you can set the value manually. >
4750
let g:arduino_dir = '/usr/share/local/arduino'
51+
<
52+
*'g:arduino_run_headless'*
53+
Run the arduino command inside a Xvfb. Requires Xvfb to be installed and in the
54+
PATH. >
55+
let g:arduino_run_headless = 1
4856
<
4957
*'g:arduino_args'*
5058
Additional arguments that will be passed to the 'arduino' command during build

Diff for: doc/tags

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'g:arduino_cmd' arduino.txt /*'g:arduino_cmd'*
55
'g:arduino_dir' arduino.txt /*'g:arduino_dir'*
66
'g:arduino_programmer' arduino.txt /*'g:arduino_programmer'*
7+
'g:arduino_run_headless' arduino.txt /*'g:arduino_run_headless'*
78
'g:arduino_serial_baud' arduino.txt /*'g:arduino_serial_baud'*
89
'g:arduino_serial_cmd' arduino.txt /*'g:arduino_serial_cmd'*
910
'g:arduino_serial_port' arduino.txt /*'g:arduino_serial_port'*

0 commit comments

Comments
 (0)