-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: add terminal resize capabilities
This adds a new size() global, which actually lives on the process.term for each process. One or both dimensions can be changed at a time, or both arguments can be omitted to return the current size.
- Loading branch information
Showing
8 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
spawn("resized.sh") | ||
match "ready" | ||
|
||
enqueue(function() | ||
local w, h = assert(size()) | ||
|
||
-- pty sizes start at 0 when we spawn off. | ||
assert(w == 0, "width is wrong, expected 0 got " .. w) | ||
assert(h == 0, "height is wrong, expected 0 got " .. h) | ||
|
||
w, h = size(w + 25, h + 80) | ||
|
||
-- Make sure that it's returning the *new* width and height when we set | ||
-- them. | ||
assert(w == 25, "width is wrong, expected 25 got " .. w) | ||
assert(h == 80, "height is wrong, expected 80 got " .. h) | ||
|
||
-- And not setting anything should still return the current dimensions. | ||
w, h = size() | ||
assert(w == 25, "width is wrong, expected 25 got " .. w) | ||
assert(h == 80, "height is wrong, expected 80 got " .. h) | ||
w, h = size(nil, nil) | ||
assert(w == 25, "width is wrong, expected 25 got " .. w) | ||
assert(h == 80, "height is wrong, expected 80 got " .. h) | ||
end) | ||
|
||
match "resized" | ||
write "^C" | ||
|
||
match "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
spawn("resized.sh") | ||
match "ready" | ||
|
||
enqueue(function() | ||
local w, h = assert(size()) | ||
|
||
assert(w == 0, "width is wrong, expected 0 got " .. w) | ||
assert(h == 0, "height is wrong, expected 0 got " .. h) | ||
|
||
w, h = size(nil, h + 80) | ||
|
||
assert(w == 0, "width is wrong, expected 0 got " .. w) | ||
assert(h == 80, "height is wrong, expected 80 got " .. h) | ||
end) | ||
|
||
match "resized" | ||
|
||
enqueue(function() | ||
local w, h = size(25) | ||
assert(w == 25, "width is wrong, expected 25 got " .. w) | ||
assert(h == 80, "height is wrong, expected 80 got " .. h) | ||
end) | ||
|
||
write "^C" | ||
match "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
|
||
loop=1 | ||
|
||
trap 'echo resized; caught=$((caught + 1))' WINCH | ||
trap 'loop=0' INT | ||
|
||
# Release the hounds now that the signal handler is setup. | ||
echo "ready" | ||
|
||
caught=0 | ||
|
||
while [ "$loop" -ne 0 ]; do | ||
sleep 1 | ||
done | ||
|
||
if [ "$caught" -eq 0 ]; then | ||
1>&2 echo "Did not observe SIGWINCH" | ||
exit 1 | ||
fi | ||
|
||
echo "$caught" |