mirror of
https://github.com/tmux/tmux.git
synced 2026-03-13 12:05:47 +00:00
Compare commits
294 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01918cb017 | ||
|
|
aa6e6fa0f2 | ||
|
|
9bdbe171b7 | ||
|
|
98a3c98c28 | ||
|
|
de2ddddd60 | ||
|
|
a9ffb56b65 | ||
|
|
14b97fc889 | ||
|
|
d0a600ccaa | ||
|
|
a368548645 | ||
|
|
13fe06a459 | ||
|
|
87e87030fe | ||
|
|
a5ef1f2ed6 | ||
|
|
f5d7a80272 | ||
|
|
33f9b316a3 | ||
|
|
d6ff630498 | ||
|
|
eceaa9a493 | ||
|
|
2e19a5ecb9 | ||
|
|
fb1f0fee5a | ||
|
|
6048b0f483 | ||
|
|
f12b857415 | ||
|
|
79bdca4638 | ||
|
|
21f8ac2766 | ||
|
|
89b56c3451 | ||
|
|
fe7486d43b | ||
|
|
400b807d75 | ||
|
|
5f07da6227 | ||
|
|
7eb3ef66e5 | ||
|
|
82776c456e | ||
|
|
80bdd89856 | ||
|
|
ed6327c87b | ||
|
|
b21a710de7 | ||
|
|
aa32457772 | ||
|
|
5c78b48cdf | ||
|
|
5fc2d4a4fc | ||
|
|
969af935f3 | ||
|
|
4f04b2094c | ||
|
|
0d88f8a78b | ||
|
|
6de991d855 | ||
|
|
ff67ef945d | ||
|
|
711b8164bb | ||
|
|
35985c0add | ||
|
|
cfc81692e6 | ||
|
|
a4a7c3c68d | ||
|
|
e7d53020b4 | ||
|
|
03519021b9 | ||
|
|
6f2698004e | ||
|
|
28a5bc8fae | ||
|
|
20154f391e | ||
|
|
98c4291df2 | ||
|
|
5c0ce192ed | ||
|
|
cc743dc296 | ||
|
|
d254293a6d | ||
|
|
850c26dd46 | ||
|
|
db07f33886 | ||
|
|
2fae6a5761 | ||
|
|
2ee0962c96 | ||
|
|
42935bde71 | ||
|
|
ffebf00585 | ||
|
|
ead6d652ff | ||
|
|
a14aa788d4 | ||
|
|
d8721b35a0 | ||
|
|
97738921cd | ||
|
|
486ce9b098 | ||
|
|
8fb6666f17 | ||
|
|
cb77c2aa78 | ||
|
|
0c94c3fbee | ||
|
|
94712a8b0d | ||
|
|
dec6ec9e29 | ||
|
|
9da78d72de | ||
|
|
d0c992306d | ||
|
|
54c2d48d7d | ||
|
|
e6cbeb4f38 | ||
|
|
4581240ced | ||
|
|
f6bad7efd7 | ||
|
|
713e0ddef3 | ||
|
|
ff45b2d343 | ||
|
|
91280f1fca | ||
|
|
7de25d86e1 | ||
|
|
ba31d3a88c | ||
|
|
54cd292f09 | ||
|
|
d1f5142dab | ||
|
|
058d2b94dc | ||
|
|
c177a627d2 | ||
|
|
8f8e0975f1 | ||
|
|
b602c1fb9a | ||
|
|
7448b38327 | ||
|
|
85d5a377c5 | ||
|
|
b9a6162d2f | ||
|
|
8f5903d7c3 | ||
|
|
f0ac0d6793 | ||
|
|
2a04665626 | ||
|
|
07c0970f54 | ||
|
|
546123f950 | ||
|
|
f2f9605c63 | ||
|
|
e4e060f2be | ||
|
|
e3b034fac7 | ||
|
|
82c0eed36d | ||
|
|
80994a8de1 | ||
|
|
9e1093b7d7 | ||
|
|
f2029f9d9e | ||
|
|
b2a2c3a1e9 | ||
|
|
f915a4bf0c | ||
|
|
91b220525b | ||
|
|
988c6bc433 | ||
|
|
1d858aa89e | ||
|
|
e24a077752 | ||
|
|
645fe9013f | ||
|
|
896c1da7da | ||
|
|
d24bd7394d | ||
|
|
aebb17dc75 | ||
|
|
d9d2f84a4b | ||
|
|
068d1b97b2 | ||
|
|
4bf6f2706e | ||
|
|
9f39652d87 | ||
|
|
c48440fd40 | ||
|
|
1afe71cc0a | ||
|
|
0e1b339c10 | ||
|
|
3dceddd70e | ||
|
|
2595718dd3 | ||
|
|
6ebd737590 | ||
|
|
e64d078a4c | ||
|
|
ae0b7c7d72 | ||
|
|
a770ef3e2a | ||
|
|
b95d1de8fd | ||
|
|
7e5262ae9a | ||
|
|
14ecb5032e | ||
|
|
1bd66b65a3 | ||
|
|
051a29ca03 | ||
|
|
c6975b3bb4 | ||
|
|
68bf7c532b | ||
|
|
9b73d76ddd | ||
|
|
5d616f4c72 | ||
|
|
8a81993ae1 | ||
|
|
b5c0b2cae2 | ||
|
|
803b8815bd | ||
|
|
785ce66ab9 | ||
|
|
640d97afd0 | ||
|
|
194e9f611b | ||
|
|
ea295ac397 | ||
|
|
5512de6a61 | ||
|
|
26792b9035 | ||
|
|
919f55ac4a | ||
|
|
2cd0ba5057 | ||
|
|
80283f99fb | ||
|
|
ced74bd72c | ||
|
|
50e3e3e72f | ||
|
|
c8a706117f | ||
|
|
0b3911631b | ||
|
|
0ca78ee51f | ||
|
|
f87d80737e | ||
|
|
9fd9952752 | ||
|
|
19f3a5c612 | ||
|
|
3c451a64b5 | ||
|
|
85c48aafff | ||
|
|
61ea49c6dd | ||
|
|
3b8f92359d | ||
|
|
182357f24b | ||
|
|
0ca9664ecf | ||
|
|
508e2f0b3a | ||
|
|
f5a37d0071 | ||
|
|
4d72b8fff7 | ||
|
|
9464b94f64 | ||
|
|
c2aa40449c | ||
|
|
3f3f13fbd7 | ||
|
|
e97daead43 | ||
|
|
623f4b12d3 | ||
|
|
5a44e18490 | ||
|
|
ab6f0bb348 | ||
|
|
4e8b1b9ac2 | ||
|
|
d81aec2439 | ||
|
|
6ae04dd5a0 | ||
|
|
968296bb07 | ||
|
|
320abba341 | ||
|
|
88711e885e | ||
|
|
7f4513ec34 | ||
|
|
2d5101621b | ||
|
|
0817132f97 | ||
|
|
24abfb72eb | ||
|
|
fe7a871a23 | ||
|
|
4e4c500879 | ||
|
|
0407d847a4 | ||
|
|
19afd842bf | ||
|
|
17d4c39f24 | ||
|
|
d9e740f86d | ||
|
|
c9037fde1c | ||
|
|
84ddc72744 | ||
|
|
75842bfe66 | ||
|
|
5849b73b81 | ||
|
|
58e9d12f23 | ||
|
|
53b25635da | ||
|
|
481703d669 | ||
|
|
b0c1cefeda | ||
|
|
2c5a6f9af5 | ||
|
|
c03565611e | ||
|
|
f32fd2df69 | ||
|
|
829fe38ab1 | ||
|
|
06684c93de | ||
|
|
d17c90583a | ||
|
|
fe26f977e6 | ||
|
|
6e99a2f4bb | ||
|
|
c9896d9554 | ||
|
|
ad417f6eb7 | ||
|
|
299c552e33 | ||
|
|
cd46568ebe | ||
|
|
937f8ed095 | ||
|
|
6ce8fe0537 | ||
|
|
c363c236aa | ||
|
|
e19df0e869 | ||
|
|
7ba5ad4cfb | ||
|
|
5c82432200 | ||
|
|
74ecc866cf | ||
|
|
b20a00f93e | ||
|
|
641a885af8 | ||
|
|
62144b9f57 | ||
|
|
43a1294ed9 | ||
|
|
58f6456af7 | ||
|
|
2c6af068d7 | ||
|
|
695dc5a153 | ||
|
|
5fddddbe21 | ||
|
|
e5ae9dd53d | ||
|
|
102df8dc80 | ||
|
|
e58d16b2df | ||
|
|
e755ca37b3 | ||
|
|
3b649d2fcd | ||
|
|
533a5719c5 | ||
|
|
aeda2e5808 | ||
|
|
392da897ff | ||
|
|
d81fa579c3 | ||
|
|
515da63d2b | ||
|
|
384736e955 | ||
|
|
6f3b6c8d92 | ||
|
|
a2681ffcee | ||
|
|
50a5f84cb4 | ||
|
|
24c387206c | ||
|
|
ba93a647f1 | ||
|
|
e1606172dd | ||
|
|
c9ec33d0d0 | ||
|
|
43264dfbf4 | ||
|
|
8d37f699ad | ||
|
|
8c29f7413b | ||
|
|
17655e5ba6 | ||
|
|
95850e1aca | ||
|
|
c1f62f1fde | ||
|
|
3887d95bca | ||
|
|
cf782c4f54 | ||
|
|
e91e8a2a6c | ||
|
|
d36ac3db15 | ||
|
|
be4c01697c | ||
|
|
0072bc65e6 | ||
|
|
37f83adca8 | ||
|
|
578a63bbc9 | ||
|
|
6b83ca0077 | ||
|
|
78ae4ee82c | ||
|
|
d6edd06749 | ||
|
|
6e8d29e9a2 | ||
|
|
8dd776106d | ||
|
|
e85213a944 | ||
|
|
26f1857154 | ||
|
|
f7a037ba26 | ||
|
|
61114c6c72 | ||
|
|
d3e8709ab5 | ||
|
|
37531673a3 | ||
|
|
31901e3c07 | ||
|
|
a34de2e378 | ||
|
|
2f6935a630 | ||
|
|
a5fd5782f8 | ||
|
|
fb02df66cc | ||
|
|
d10def5b0b | ||
|
|
2357bfb254 | ||
|
|
87babfa473 | ||
|
|
eb9839fd32 | ||
|
|
6e5121be7e | ||
|
|
4efd41f3af | ||
|
|
99351c9cae | ||
|
|
60074a6bc6 | ||
|
|
a3967de9a5 | ||
|
|
044019d9d6 | ||
|
|
db44151a37 | ||
|
|
ceab7154d4 | ||
|
|
0b4c408168 | ||
|
|
f069c0ba09 | ||
|
|
9c4caf49a2 | ||
|
|
2be01ab4ec | ||
|
|
b462063cd5 | ||
|
|
8aaf86a6ea | ||
|
|
88517ceebb | ||
|
|
6a292f09ba | ||
|
|
ff526e43de | ||
|
|
d563aa7c7b | ||
|
|
ae5a62a514 | ||
|
|
c86d83f835 | ||
|
|
9a1b9f15a1 | ||
|
|
af2c7ce646 | ||
|
|
b541a97821 |
98
CHANGES
98
CHANGES
@@ -1,3 +1,101 @@
|
|||||||
|
CHANGES FROM 2.7 to 2.8
|
||||||
|
|
||||||
|
* Make display-panes block the client until a pane is chosen or it
|
||||||
|
times out.
|
||||||
|
|
||||||
|
* Clear history on RIS like most other terminals do.
|
||||||
|
|
||||||
|
* Add an "Any" key to run a command if a key is pressed that is not
|
||||||
|
bound in the current key table.
|
||||||
|
|
||||||
|
* Expand formats in load-buffer and save-buffer.
|
||||||
|
|
||||||
|
* Add a rectangle_toggle format.
|
||||||
|
|
||||||
|
* Add set-hook -R to run a hook immediately.
|
||||||
|
|
||||||
|
* Add README.ja.
|
||||||
|
|
||||||
|
* Add pane focus hooks.
|
||||||
|
|
||||||
|
* Allow any punctuation as separator for s/x/y not only /.
|
||||||
|
|
||||||
|
* Improve resizing with the mouse (fix resizing the wrong pane in some
|
||||||
|
layouts, and allow resizing multiple panes at the same time).
|
||||||
|
|
||||||
|
* Allow , and } to be escaped in formats as #, and #}.
|
||||||
|
|
||||||
|
* Add KRB5CCNAME to update-environment.
|
||||||
|
|
||||||
|
* Change meaning of -c to display-message so the client is used if it
|
||||||
|
matches the session given to -t.
|
||||||
|
|
||||||
|
* Fixes to : form of SGR.
|
||||||
|
|
||||||
|
* Add x and X to choose-tree to kill sessions, windows or panes.
|
||||||
|
|
||||||
|
CHANGES FROM 2.6 TO 2.7
|
||||||
|
|
||||||
|
* Remove EVENT_* variables from environment on platforms where tmux uses them
|
||||||
|
so they do not pass on to panes.
|
||||||
|
|
||||||
|
* Fixes for hooks at server exit.
|
||||||
|
|
||||||
|
* Remove SGR 10 (was equivalent to SGR 0 but no other terminal seems to do
|
||||||
|
this).
|
||||||
|
|
||||||
|
* Expand formats in window and session names.
|
||||||
|
|
||||||
|
* Add -Z flag to choose-tree, choose-client, choose-buffer to automatically
|
||||||
|
zoom the pane when the mode is entered and unzoom when it exits, assuming the
|
||||||
|
pane is not already zoomed. This is now part of the default key bindings.
|
||||||
|
|
||||||
|
* Add C-g to exit modes with emacs keys.
|
||||||
|
|
||||||
|
* Add exit-empty option to exit server if no sessions (defaults to on).
|
||||||
|
|
||||||
|
* Show if a filter is present in choose modes.
|
||||||
|
|
||||||
|
* Add pipe-pane -I to to connect stdin of the child process.
|
||||||
|
|
||||||
|
* Performance improvements for reflow.
|
||||||
|
|
||||||
|
* Use RGB terminfo(5) capability to detect RGB colour terminals (the existing
|
||||||
|
Tc extension remains unchanged).
|
||||||
|
|
||||||
|
* Support for ISO colon-separated SGR sequences.
|
||||||
|
|
||||||
|
* Add select-layout -E to spread panes out evenly (bound to E key).
|
||||||
|
|
||||||
|
* Support wide characters properly when reflowing.
|
||||||
|
|
||||||
|
* Pass PWD to new panes as a hint to shells, as well as calling chdir().
|
||||||
|
|
||||||
|
* Performance improvements for the various choose modes.
|
||||||
|
|
||||||
|
* Only show first member of session groups in tree mode (-G flag to choose-tree
|
||||||
|
to show all).
|
||||||
|
|
||||||
|
* Support %else in config files to match %if; from Brad Town in GitHub issue
|
||||||
|
1071.
|
||||||
|
|
||||||
|
* Fix "kind" terminfo(5) capability to be S-Down not S-Up.
|
||||||
|
|
||||||
|
* Add a box around the preview label in tree mode.
|
||||||
|
|
||||||
|
* Show exit status and time in the remain-on-exit pane text; from Timo
|
||||||
|
Boettcher in GitHub issue 1103.
|
||||||
|
|
||||||
|
* Correctly use pane-base-index in tree mode.
|
||||||
|
|
||||||
|
* Change the allow-rename option default to off.
|
||||||
|
|
||||||
|
* Support for xterm(1) title stack escape sequences (GitHub issue 1075 from
|
||||||
|
Brad Town).
|
||||||
|
|
||||||
|
* Correctly remove padding cells to fix a UTF-8 display problem (GitHub issue
|
||||||
|
1090).
|
||||||
|
|
||||||
CHANGES FROM 2.5 TO 2.6, 05 October 2017
|
CHANGES FROM 2.5 TO 2.6, 05 October 2017
|
||||||
|
|
||||||
* Add select-pane -T to set pane title.
|
* Add select-pane -T to set pane title.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ CLEANFILES = tmux.1.mdoc tmux.1.man
|
|||||||
|
|
||||||
# Distribution tarball options.
|
# Distribution tarball options.
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
CHANGES README COPYING example_tmux.conf compat/*.[ch] \
|
CHANGES README README.ja COPYING example_tmux.conf compat/*.[ch] \
|
||||||
osdep-*.c mdoc2man.awk tmux.1
|
osdep-*.c mdoc2man.awk tmux.1
|
||||||
|
|
||||||
# Preprocessor flags.
|
# Preprocessor flags.
|
||||||
|
|||||||
11
README
11
README
@@ -1,8 +1,8 @@
|
|||||||
Welcome to tmux!
|
Welcome to tmux!
|
||||||
|
|
||||||
tmux is a "terminal multiplexer", it enables a number of terminals (or windows)
|
tmux is a terminal multiplexer: it enables a number of terminals to be created,
|
||||||
to be accessed and controlled from a single terminal. tmux is intended to be a
|
accessed, and controlled from a single screen. tmux may be detached from a
|
||||||
simple, modern, BSD-licensed alternative to programs such as GNU screen.
|
screen and continue running in the background, then later reattached.
|
||||||
|
|
||||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, OS X and Solaris.
|
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, OS X and Solaris.
|
||||||
|
|
||||||
@@ -43,11 +43,6 @@ the source tree with:
|
|||||||
|
|
||||||
A small example configuration in example_tmux.conf.
|
A small example configuration in example_tmux.conf.
|
||||||
|
|
||||||
A vim(1) syntax file is available at:
|
|
||||||
|
|
||||||
https://github.com/ericpruitt/tmux.vim
|
|
||||||
https://raw.githubusercontent.com/ericpruitt/tmux.vim/master/vim/syntax/tmux.vim
|
|
||||||
|
|
||||||
And a bash(1) completion file at:
|
And a bash(1) completion file at:
|
||||||
|
|
||||||
https://github.com/imomaliev/tmux-bash-completion
|
https://github.com/imomaliev/tmux-bash-completion
|
||||||
|
|||||||
62
README.ja
Normal file
62
README.ja
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
tmuxへようこそ!
|
||||||
|
|
||||||
|
tmuxはターミナルマルチプレクサーです。複数のターミナルを一つのスクリーン内に作成し、操作することができます。
|
||||||
|
バックグラウンドで処理を実行中に一度スクリーンから離れて後から復帰することも可能です。
|
||||||
|
|
||||||
|
OpenBSD、FreeBSD、NetBSD、Linux、OS X、Solarisで実行できます。
|
||||||
|
|
||||||
|
tmuxはlibevent 2.x.に依存します。 下記からダウンロードしてください。
|
||||||
|
|
||||||
|
http://libevent.org
|
||||||
|
|
||||||
|
また、ncursesも必要です。こちらからどうぞ。
|
||||||
|
|
||||||
|
http://invisible-island.net/ncurses/
|
||||||
|
|
||||||
|
tarballでのtmuxのビルドとインストール方法。
|
||||||
|
|
||||||
|
$ ./configure && make
|
||||||
|
$ sudo make install
|
||||||
|
|
||||||
|
tmuxはutmp(5)をアップデートするためにutempterを使うことができます。もしインストール済みであればオプション「--enable-utempter」をつけて実行してください。
|
||||||
|
|
||||||
|
リポジトリから最新バージョンを手に入れるためには下記を実行。
|
||||||
|
|
||||||
|
$ git clone https://github.com/tmux/tmux.git
|
||||||
|
$ cd tmux
|
||||||
|
$ sh autogen.sh
|
||||||
|
$ ./configure && make
|
||||||
|
|
||||||
|
(ビルドのためにはlibevent、ncurses libraries、headersに加えて、C compiler、make、autoconf、automake、pkg-configが必要です。)
|
||||||
|
|
||||||
|
詳しい情報はhttp://git-scm.comをご覧ください。修正はメール<tmux-users@googlegroups.com>宛、もしくはhttps://github.com/tmux/tmux/issuesにて受け付けています。
|
||||||
|
|
||||||
|
tmuxのドキュメントについてはtmux.1マニュアルをご覧ください。こちらのコマンドで参照可能です。
|
||||||
|
|
||||||
|
$ nroff -mdoc tmux.1|less
|
||||||
|
|
||||||
|
サンプル設定は本リポジトリのexample_tmux.confに
|
||||||
|
また、bash-completionファイルは下記にあります。
|
||||||
|
|
||||||
|
https://github.com/imomaliev/tmux-bash-completion
|
||||||
|
|
||||||
|
「-v」や「-vv」を指定することでデバッグモードでの起動が可能です。カレントディレクトリにサーバーやクライアントのログファイルが生成されます。
|
||||||
|
|
||||||
|
議論やバグレポート用のメーリングリストにはこちらから参加可能です。
|
||||||
|
|
||||||
|
https://groups.google.com/forum/#!forum/tmux-users
|
||||||
|
|
||||||
|
gitコミットについての連絡先
|
||||||
|
|
||||||
|
https://groups.google.com/forum/#!forum/tmux-git
|
||||||
|
|
||||||
|
購読は<tmux-users+subscribe@googlegroups.com>までメールをお願いします。
|
||||||
|
|
||||||
|
バグレポートや機能追加(特にコードへの貢献)は大歓迎です。こちらにご連絡ください。
|
||||||
|
|
||||||
|
tmux-users@googlegroups.com
|
||||||
|
|
||||||
|
本ファイル、CHANGES、 FAQ、SYNCINGそしてTODOはISC licenseで保護されています。
|
||||||
|
その他のファイルのライセンスや著作権については、ファイルの上部に明記されています。
|
||||||
|
|
||||||
|
-- Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||||
15
TODO
15
TODO
@@ -49,6 +49,7 @@
|
|||||||
* improve word and line selection in copy mode (for example when
|
* improve word and line selection in copy mode (for example when
|
||||||
dragging it should select by word. compare how xterm works. GitHub
|
dragging it should select by word. compare how xterm works. GitHub
|
||||||
issue 682)
|
issue 682)
|
||||||
|
* key to search for word under cursor (GitHub issue 1240)
|
||||||
|
|
||||||
- layout stuff
|
- layout stuff
|
||||||
* way to tag a layout as a number/name
|
* way to tag a layout as a number/name
|
||||||
@@ -110,21 +111,23 @@
|
|||||||
bind -n DoubleClick3Status confirm-before -p "kill-window #I? (y/n)" kill-window
|
bind -n DoubleClick3Status confirm-before -p "kill-window #I? (y/n)" kill-window
|
||||||
* respawn -c flag same as neww etc
|
* respawn -c flag same as neww etc
|
||||||
* marker lines in history (GitHub issue 1042)
|
* marker lines in history (GitHub issue 1042)
|
||||||
* tree mode stuff: predefined filters, tag-all key, ...
|
* tree mode stuff: make command prompt (:) common code so all modes get it,
|
||||||
|
predefined filters, tag-all key, ...
|
||||||
|
* drag panes and windows around to move/swap them in choose mode
|
||||||
|
|
||||||
- hooks
|
- hooks
|
||||||
* more hooks for various things
|
* more hooks for various things
|
||||||
* finish after hooks for special commands. these do not have a hook at
|
* finish after hooks for special commands. these do not have a hook at
|
||||||
the moment:
|
the moment:
|
||||||
attach-session detach-client kill-server respawn-window
|
attach-session detach-client kill-server respawn-window
|
||||||
swap-window break-pane find-window kill-session rotate-window
|
swap-window break-pane find-window kill-session rotate-window
|
||||||
switch-client choose-tree if-shell kill-window run-shell
|
switch-client choose-tree if-shell kill-window run-shell
|
||||||
wait-for command-prompt join-pane move-window source-file
|
wait-for command-prompt join-pane move-window source-file
|
||||||
confirm-before kill-pane respawn-pane swap-pane
|
confirm-before kill-pane respawn-pane swap-pane
|
||||||
at the moment AFTERHOOK uses current only if target is not valid,
|
at the moment AFTERHOOK uses current only if target is not valid,
|
||||||
but target is ALWAYS valid - it should use current if no -t flag?
|
but target is ALWAYS valid - it should use current if no -t flag?
|
||||||
then select-* could use AFTERHOOK
|
then select-* could use AFTERHOOK
|
||||||
* multiple hooks with the same name?
|
* multiple hooks with the same name?
|
||||||
* finish hooks for notifys
|
* finish hooks for notifys
|
||||||
* for session_closed, if no sessions at all, perhaps fake up a
|
* for session_closed, if no sessions at all, perhaps fake up a
|
||||||
temporary one
|
temporary one
|
||||||
|
|||||||
12
alerts.c
12
alerts.c
@@ -200,8 +200,10 @@ alerts_check_bell(struct window *w)
|
|||||||
* not check WINLINK_BELL).
|
* not check WINLINK_BELL).
|
||||||
*/
|
*/
|
||||||
s = wl->session;
|
s = wl->session;
|
||||||
if (s->curw != wl)
|
if (s->curw != wl) {
|
||||||
wl->flags |= WINLINK_BELL;
|
wl->flags |= WINLINK_BELL;
|
||||||
|
server_status_session(s);
|
||||||
|
}
|
||||||
if (!alerts_action_applies(wl, "bell-action"))
|
if (!alerts_action_applies(wl, "bell-action"))
|
||||||
continue;
|
continue;
|
||||||
notify_winlink("alert-bell", wl);
|
notify_winlink("alert-bell", wl);
|
||||||
@@ -234,8 +236,10 @@ alerts_check_activity(struct window *w)
|
|||||||
if (wl->flags & WINLINK_ACTIVITY)
|
if (wl->flags & WINLINK_ACTIVITY)
|
||||||
continue;
|
continue;
|
||||||
s = wl->session;
|
s = wl->session;
|
||||||
if (s->curw != wl)
|
if (s->curw != wl) {
|
||||||
wl->flags |= WINLINK_ACTIVITY;
|
wl->flags |= WINLINK_ACTIVITY;
|
||||||
|
server_status_session(s);
|
||||||
|
}
|
||||||
if (!alerts_action_applies(wl, "activity-action"))
|
if (!alerts_action_applies(wl, "activity-action"))
|
||||||
continue;
|
continue;
|
||||||
notify_winlink("alert-activity", wl);
|
notify_winlink("alert-activity", wl);
|
||||||
@@ -268,8 +272,10 @@ alerts_check_silence(struct window *w)
|
|||||||
if (wl->flags & WINLINK_SILENCE)
|
if (wl->flags & WINLINK_SILENCE)
|
||||||
continue;
|
continue;
|
||||||
s = wl->session;
|
s = wl->session;
|
||||||
if (s->curw != wl)
|
if (s->curw != wl) {
|
||||||
wl->flags |= WINLINK_SILENCE;
|
wl->flags |= WINLINK_SILENCE;
|
||||||
|
server_status_session(s);
|
||||||
|
}
|
||||||
if (!alerts_action_applies(wl, "silence-action"))
|
if (!alerts_action_applies(wl, "silence-action"))
|
||||||
continue;
|
continue;
|
||||||
notify_winlink("alert-silence", wl);
|
notify_winlink("alert-silence", wl);
|
||||||
|
|||||||
174
cfg.c
174
cfg.c
@@ -26,6 +26,17 @@
|
|||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/* Condition for %if, %elif, %else and %endif. */
|
||||||
|
struct cfg_cond {
|
||||||
|
size_t line; /* line number of %if */
|
||||||
|
int met; /* condition was met */
|
||||||
|
int skip; /* skip later %elif/%else */
|
||||||
|
int saw_else; /* saw a %else */
|
||||||
|
|
||||||
|
TAILQ_ENTRY(cfg_cond) entry;
|
||||||
|
};
|
||||||
|
TAILQ_HEAD(cfg_conds, cfg_cond);
|
||||||
|
|
||||||
static char *cfg_file;
|
static char *cfg_file;
|
||||||
int cfg_finished;
|
int cfg_finished;
|
||||||
static char **cfg_causes;
|
static char **cfg_causes;
|
||||||
@@ -101,6 +112,124 @@ start_cfg(void)
|
|||||||
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
|
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
cfg_check_condition(const char *path, size_t line, const char *p, int *skip)
|
||||||
|
{
|
||||||
|
struct format_tree *ft;
|
||||||
|
char *s;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
while (isspace((u_char)*p))
|
||||||
|
p++;
|
||||||
|
if (p[0] == '\0') {
|
||||||
|
cfg_add_cause("%s:%zu: invalid condition", path, line);
|
||||||
|
*skip = 1;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ft = format_create(NULL, NULL, FORMAT_NONE, FORMAT_NOJOBS);
|
||||||
|
s = format_expand(ft, p);
|
||||||
|
result = format_true(s);
|
||||||
|
free(s);
|
||||||
|
format_free(ft);
|
||||||
|
|
||||||
|
*skip = result;
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cfg_handle_if(const char *path, size_t line, struct cfg_conds *conds,
|
||||||
|
const char *p)
|
||||||
|
{
|
||||||
|
struct cfg_cond *cond;
|
||||||
|
struct cfg_cond *parent = TAILQ_FIRST(conds);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add a new condition. If a previous condition exists and isn't
|
||||||
|
* currently met, this new one also can't be met.
|
||||||
|
*/
|
||||||
|
cond = xcalloc(1, sizeof *cond);
|
||||||
|
cond->line = line;
|
||||||
|
if (parent == NULL || parent->met)
|
||||||
|
cond->met = cfg_check_condition(path, line, p, &cond->skip);
|
||||||
|
else
|
||||||
|
cond->skip = 1;
|
||||||
|
cond->saw_else = 0;
|
||||||
|
TAILQ_INSERT_HEAD(conds, cond, entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cfg_handle_elif(const char *path, size_t line, struct cfg_conds *conds,
|
||||||
|
const char *p)
|
||||||
|
{
|
||||||
|
struct cfg_cond *cond = TAILQ_FIRST(conds);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If a previous condition exists and wasn't met, check this
|
||||||
|
* one instead and change the state.
|
||||||
|
*/
|
||||||
|
if (cond == NULL || cond->saw_else)
|
||||||
|
cfg_add_cause("%s:%zu: unexpected %%elif", path, line);
|
||||||
|
else if (!cond->skip)
|
||||||
|
cond->met = cfg_check_condition(path, line, p, &cond->skip);
|
||||||
|
else
|
||||||
|
cond->met = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cfg_handle_else(const char *path, size_t line, struct cfg_conds *conds)
|
||||||
|
{
|
||||||
|
struct cfg_cond *cond = TAILQ_FIRST(conds);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If a previous condition exists and wasn't met and wasn't already
|
||||||
|
* %else, use this one instead.
|
||||||
|
*/
|
||||||
|
if (cond == NULL || cond->saw_else) {
|
||||||
|
cfg_add_cause("%s:%zu: unexpected %%else", path, line);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cond->saw_else = 1;
|
||||||
|
cond->met = !cond->skip;
|
||||||
|
cond->skip = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cfg_handle_endif(const char *path, size_t line, struct cfg_conds *conds)
|
||||||
|
{
|
||||||
|
struct cfg_cond *cond = TAILQ_FIRST(conds);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove previous condition if one exists.
|
||||||
|
*/
|
||||||
|
if (cond == NULL) {
|
||||||
|
cfg_add_cause("%s:%zu: unexpected %%endif", path, line);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TAILQ_REMOVE(conds, cond, entry);
|
||||||
|
free(cond);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cfg_handle_directive(const char *p, const char *path, size_t line,
|
||||||
|
struct cfg_conds *conds)
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
while (p[n] != '\0' && !isspace((u_char)p[n]))
|
||||||
|
n++;
|
||||||
|
if (strncmp(p, "%if", n) == 0)
|
||||||
|
cfg_handle_if(path, line, conds, p + n);
|
||||||
|
else if (strncmp(p, "%elif", n) == 0)
|
||||||
|
cfg_handle_elif(path, line, conds, p + n);
|
||||||
|
else if (strcmp(p, "%else") == 0)
|
||||||
|
cfg_handle_else(path, line, conds);
|
||||||
|
else if (strcmp(p, "%endif") == 0)
|
||||||
|
cfg_handle_endif(path, line, conds);
|
||||||
|
else
|
||||||
|
cfg_add_cause("%s:%zu: invalid directive: %s", path, line, p);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
||||||
{
|
{
|
||||||
@@ -108,11 +237,13 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
|||||||
const char delim[3] = { '\\', '\\', '\0' };
|
const char delim[3] = { '\\', '\\', '\0' };
|
||||||
u_int found = 0;
|
u_int found = 0;
|
||||||
size_t line = 0;
|
size_t line = 0;
|
||||||
char *buf, *cause1, *p, *q, *s;
|
char *buf, *cause1, *p, *q;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
struct cmdq_item *new_item;
|
struct cmdq_item *new_item;
|
||||||
int condition = 0;
|
struct cfg_cond *cond, *cond1;
|
||||||
struct format_tree *ft;
|
struct cfg_conds conds;
|
||||||
|
|
||||||
|
TAILQ_INIT(&conds);
|
||||||
|
|
||||||
log_debug("loading %s", path);
|
log_debug("loading %s", path);
|
||||||
if ((f = fopen(path, "rb")) == NULL) {
|
if ((f = fopen(path, "rb")) == NULL) {
|
||||||
@@ -136,33 +267,12 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
|||||||
while (q != p && isspace((u_char)*q))
|
while (q != p && isspace((u_char)*q))
|
||||||
*q-- = '\0';
|
*q-- = '\0';
|
||||||
|
|
||||||
if (condition != 0 && strcmp(p, "%endif") == 0) {
|
if (*p == '%') {
|
||||||
condition = 0;
|
cfg_handle_directive(p, path, line, &conds);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strncmp(p, "%if ", 4) == 0) {
|
cond = TAILQ_FIRST(&conds);
|
||||||
if (condition != 0) {
|
if (cond != NULL && !cond->met)
|
||||||
cfg_add_cause("%s:%zu: nested %%if", path,
|
|
||||||
line);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ft = format_create(NULL, NULL, FORMAT_NONE,
|
|
||||||
FORMAT_NOJOBS);
|
|
||||||
|
|
||||||
s = p + 3;
|
|
||||||
while (isspace((u_char)*s))
|
|
||||||
s++;
|
|
||||||
s = format_expand(ft, s);
|
|
||||||
if (*s != '\0' && (s[0] != '0' || s[1] != '\0'))
|
|
||||||
condition = 1;
|
|
||||||
else
|
|
||||||
condition = -1;
|
|
||||||
free(s);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (condition == -1)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
cmdlist = cmd_string_parse(p, path, line, &cause1);
|
cmdlist = cmd_string_parse(p, path, line, &cause1);
|
||||||
@@ -176,8 +286,6 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
|||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
if (cmdlist == NULL)
|
|
||||||
continue;
|
|
||||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
cmdq_insert_after(item, new_item);
|
cmdq_insert_after(item, new_item);
|
||||||
@@ -189,6 +297,12 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
|||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
TAILQ_FOREACH_REVERSE_SAFE(cond, &conds, cfg_conds, entry, cond1) {
|
||||||
|
cfg_add_cause("%s:%zu: unterminated %%if", path, cond->line);
|
||||||
|
TAILQ_REMOVE(&conds, cond, entry);
|
||||||
|
free(cond);
|
||||||
|
}
|
||||||
|
|
||||||
return (found);
|
return (found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
client.c
16
client.c
@@ -17,11 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/file.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <event.h>
|
#include <event.h>
|
||||||
@@ -278,10 +277,10 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
client_peer = proc_add_peer(client_proc, fd, client_dispatch, NULL);
|
client_peer = proc_add_peer(client_proc, fd, client_dispatch, NULL);
|
||||||
|
|
||||||
/* Save these before pledge(). */
|
/* Save these before pledge(). */
|
||||||
if ((cwd = getcwd(path, sizeof path)) == NULL) {
|
if ((cwd = getenv("PWD")) == NULL &&
|
||||||
if ((cwd = find_home()) == NULL)
|
(cwd = getcwd(path, sizeof path)) == NULL &&
|
||||||
cwd = "/";
|
(cwd = find_home()) == NULL)
|
||||||
}
|
cwd = "/";
|
||||||
if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
|
if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
|
||||||
ttynam = "";
|
ttynam = "";
|
||||||
|
|
||||||
@@ -338,6 +337,10 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
size = 0;
|
size = 0;
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
size += strlen(argv[i]) + 1;
|
size += strlen(argv[i]) + 1;
|
||||||
|
if (size > MAX_IMSGSIZE - (sizeof *data)) {
|
||||||
|
fprintf(stderr, "command too long\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
data = xmalloc((sizeof *data) + size);
|
data = xmalloc((sizeof *data) + size);
|
||||||
|
|
||||||
/* Prepare command for server. */
|
/* Prepare command for server. */
|
||||||
@@ -449,6 +452,7 @@ client_write(int fd, const char *data, size_t size)
|
|||||||
{
|
{
|
||||||
ssize_t used;
|
ssize_t used;
|
||||||
|
|
||||||
|
log_debug("%s: %.*s", __func__, (int)size, data);
|
||||||
while (size != 0) {
|
while (size != 0) {
|
||||||
used = write(fd, data, size);
|
used = write(fd, data, size);
|
||||||
if (used == -1) {
|
if (used == -1) {
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
|||||||
s->cwd = format_single(item, cflag, c, s, wl, wp);
|
s->cwd = format_single(item, cflag, c, s, wl, wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c->last_session = c->session;
|
||||||
if (c->session != NULL) {
|
if (c->session != NULL) {
|
||||||
if (dflag) {
|
if (dflag) {
|
||||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
TAILQ_FOREACH(c_loop, &clients, entry) {
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ const struct cmd_entry cmd_choose_tree_entry = {
|
|||||||
.name = "choose-tree",
|
.name = "choose-tree",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "F:f:NO:st:w", 0, 1 },
|
.args = { "F:Gf:NO:st:wZ", 0, 1 },
|
||||||
.usage = "[-Nsw] [-F format] [-f filter] [-O sort-order] "
|
.usage = "[-GNsw] [-F format] [-f filter] [-O sort-order] "
|
||||||
CMD_TARGET_PANE_USAGE,
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
@@ -44,7 +44,7 @@ const struct cmd_entry cmd_choose_client_entry = {
|
|||||||
.name = "choose-client",
|
.name = "choose-client",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "F:f:NO:t:", 0, 1 },
|
.args = { "F:f:NO:t:Z", 0, 1 },
|
||||||
.usage = "[-N] [-F format] [-f filter] [-O sort-order] "
|
.usage = "[-N] [-F format] [-f filter] [-O sort-order] "
|
||||||
CMD_TARGET_PANE_USAGE,
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ const struct cmd_entry cmd_choose_buffer_entry = {
|
|||||||
.name = "choose-buffer",
|
.name = "choose-buffer",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "F:f:NO:t:", 0, 1 },
|
.args = { "F:f:NO:t:Z", 0, 1 },
|
||||||
.usage = "[-N] [-F format] [-f filter] [-O sort-order] "
|
.usage = "[-N] [-F format] [-f filter] [-O sort-order] "
|
||||||
CMD_TARGET_PANE_USAGE,
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ static enum cmd_retval
|
|||||||
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
struct client *c;
|
struct client *c, *target_c;
|
||||||
struct session *s = item->target.s;
|
struct session *s = item->target.s;
|
||||||
struct winlink *wl = item->target.wl;
|
struct winlink *wl = item->target.wl;
|
||||||
struct window_pane *wp = item->target.wp;
|
struct window_pane *wp = item->target.wp;
|
||||||
@@ -65,7 +65,6 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cmdq_error(item, "only one of -F or argument must be given");
|
cmdq_error(item, "only one of -F or argument must be given");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
c = cmd_find_client(item, args_get(args, 'c'), 1);
|
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
template = args_get(args, 'F');
|
||||||
if (args->argc != 0)
|
if (args->argc != 0)
|
||||||
@@ -73,8 +72,19 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (template == NULL)
|
if (template == NULL)
|
||||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
template = DISPLAY_MESSAGE_TEMPLATE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -c is intended to be the client where the message should be
|
||||||
|
* displayed if -p is not given. But it makes sense to use it for the
|
||||||
|
* formats too, assuming it matches the session. If it doesn't, use the
|
||||||
|
* best client for the session.
|
||||||
|
*/
|
||||||
|
c = cmd_find_client(item, args_get(args, 'c'), 1);
|
||||||
|
if (c != NULL && c->session == s)
|
||||||
|
target_c = c;
|
||||||
|
else
|
||||||
|
target_c = cmd_find_best_client(s);
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||||
format_defaults(ft, c, s, wl, wp);
|
format_defaults(ft, target_c, s, wl, wp);
|
||||||
|
|
||||||
msg = format_expand_time(ft, template, time(NULL));
|
msg = format_expand_time(ft, template, time(NULL));
|
||||||
if (args_has(self->args, 'p'))
|
if (args_has(self->args, 'p'))
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
|
s = c->session;
|
||||||
|
|
||||||
if (c->identify_callback != NULL)
|
if (c->identify_callback != NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
@@ -64,7 +65,7 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
c->identify_callback_data = xstrdup(args->argv[0]);
|
c->identify_callback_data = xstrdup(args->argv[0]);
|
||||||
else
|
else
|
||||||
c->identify_callback_data = xstrdup("select-pane -t '%%'");
|
c->identify_callback_data = xstrdup("select-pane -t '%%'");
|
||||||
s = c->session;
|
c->identify_callback_item = item;
|
||||||
|
|
||||||
if (args_has(args, 'd')) {
|
if (args_has(args, 'd')) {
|
||||||
delay = args_strtonum(args, 'd', 0, UINT_MAX, &cause);
|
delay = args_strtonum(args, 'd', 0, UINT_MAX, &cause);
|
||||||
@@ -77,7 +78,7 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
delay = options_get_number(s->options, "display-panes-time");
|
delay = options_get_number(s->options, "display-panes-time");
|
||||||
server_client_set_identify(c, delay);
|
server_client_set_identify(c, delay);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
static enum cmd_retval
|
||||||
@@ -96,34 +97,36 @@ cmd_display_panes_callback(struct client *c, struct window_pane *wp)
|
|||||||
{
|
{
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
struct cmdq_item *new_item;
|
struct cmdq_item *new_item;
|
||||||
char *template, *cmd, *expanded, *cause;
|
char *cmd, *expanded, *cause;
|
||||||
|
|
||||||
template = c->identify_callback_data;
|
|
||||||
if (wp == NULL)
|
if (wp == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
xasprintf(&expanded, "%%%u", wp->id);
|
xasprintf(&expanded, "%%%u", wp->id);
|
||||||
cmd = cmd_template_replace(template, expanded, 1);
|
cmd = cmd_template_replace(c->identify_callback_data, expanded, 1);
|
||||||
|
|
||||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||||
if (cmdlist == NULL) {
|
if (cmdlist == NULL && cause != NULL)
|
||||||
if (cause != NULL) {
|
new_item = cmdq_get_callback(cmd_display_panes_error, cause);
|
||||||
new_item = cmdq_get_callback(cmd_display_panes_error,
|
else if (cmdlist == NULL)
|
||||||
cause);
|
new_item = NULL;
|
||||||
} else
|
else {
|
||||||
new_item = NULL;
|
|
||||||
} else {
|
|
||||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||||
cmd_list_free(cmdlist);
|
cmd_list_free(cmdlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_item != NULL)
|
if (new_item != NULL)
|
||||||
cmdq_append(c, new_item);
|
cmdq_insert_after(c->identify_callback_item, new_item);
|
||||||
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
free(expanded);
|
free(expanded);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
c->identify_callback_item->flags &= ~CMDQ_WAITING;
|
||||||
|
c->identify_callback_item = NULL;
|
||||||
|
|
||||||
free(c->identify_callback_data);
|
free(c->identify_callback_data);
|
||||||
c->identify_callback_data = NULL;
|
c->identify_callback_data = NULL;
|
||||||
|
|
||||||
c->identify_callback = NULL;
|
c->identify_callback = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
69
cmd-find.c
69
cmd-find.c
@@ -34,6 +34,7 @@ static int cmd_find_best_winlink_with_window(struct cmd_find_state *);
|
|||||||
|
|
||||||
static const char *cmd_find_map_table(const char *[][2], const char *);
|
static const char *cmd_find_map_table(const char *[][2], const char *);
|
||||||
|
|
||||||
|
static void cmd_find_log_state(const char *, struct cmd_find_state *);
|
||||||
static int cmd_find_get_session(struct cmd_find_state *, const char *);
|
static int cmd_find_get_session(struct cmd_find_state *, const char *);
|
||||||
static int cmd_find_get_window(struct cmd_find_state *, const char *, int);
|
static int cmd_find_get_window(struct cmd_find_state *, const char *, int);
|
||||||
static int cmd_find_get_window_with_session(struct cmd_find_state *,
|
static int cmd_find_get_window_with_session(struct cmd_find_state *,
|
||||||
@@ -82,6 +83,7 @@ cmd_find_try_TMUX(struct client *c)
|
|||||||
char tmp[256];
|
char tmp[256];
|
||||||
long long pid;
|
long long pid;
|
||||||
u_int session;
|
u_int session;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
envent = environ_find(c->environ, "TMUX");
|
envent = environ_find(c->environ, "TMUX");
|
||||||
if (envent == NULL)
|
if (envent == NULL)
|
||||||
@@ -91,8 +93,13 @@ cmd_find_try_TMUX(struct client *c)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
if (pid != getpid())
|
if (pid != getpid())
|
||||||
return (NULL);
|
return (NULL);
|
||||||
log_debug("client %p TMUX %s (session @%u)", c, envent->value, session);
|
log_debug("%s: client %p TMUX %s (session $%u)", __func__, c,
|
||||||
return (session_find_by_id(session));
|
envent->value, session);
|
||||||
|
|
||||||
|
s = session_find_by_id(session);
|
||||||
|
if (s != NULL)
|
||||||
|
log_debug("%s: session $%u still exists", __func__, s->id);
|
||||||
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find pane containing client if any. */
|
/* Find pane containing client if any. */
|
||||||
@@ -105,9 +112,11 @@ cmd_find_inside_pane(struct client *c)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
|
RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
|
||||||
if (strcmp(wp->tty, c->ttyname) == 0)
|
if (wp->fd != -1 && strcmp(wp->tty, c->ttyname) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (wp != NULL)
|
||||||
|
log_debug("%s: got pane %%%u (%s)", __func__, wp->id, wp->tty);
|
||||||
return (wp);
|
return (wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +130,7 @@ cmd_find_client_better(struct client *c, struct client *than)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Find best client for session. */
|
/* Find best client for session. */
|
||||||
static struct client *
|
struct client *
|
||||||
cmd_find_best_client(struct session *s)
|
cmd_find_best_client(struct session *s)
|
||||||
{
|
{
|
||||||
struct client *c_loop, *c;
|
struct client *c_loop, *c;
|
||||||
@@ -166,6 +175,8 @@ cmd_find_best_session(struct session **slist, u_int ssize, int flags)
|
|||||||
struct session *s_loop, *s;
|
struct session *s_loop, *s;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
|
log_debug("%s: %u sessions to try", __func__, ssize);
|
||||||
|
|
||||||
s = NULL;
|
s = NULL;
|
||||||
if (slist != NULL) {
|
if (slist != NULL) {
|
||||||
for (i = 0; i < ssize; i++) {
|
for (i = 0; i < ssize; i++) {
|
||||||
@@ -189,6 +200,8 @@ cmd_find_best_session_with_window(struct cmd_find_state *fs)
|
|||||||
u_int ssize;
|
u_int ssize;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
|
|
||||||
|
log_debug("%s: window is @%u", __func__, fs->w->id);
|
||||||
|
|
||||||
ssize = 0;
|
ssize = 0;
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
if (!session_has(s, fs->w))
|
if (!session_has(s, fs->w))
|
||||||
@@ -210,7 +223,7 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find the best winlink for a window (the current if it contains the pane,
|
* Find the best winlink for a window (the current if it contains the window,
|
||||||
* otherwise the first).
|
* otherwise the first).
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
@@ -218,6 +231,8 @@ cmd_find_best_winlink_with_window(struct cmd_find_state *fs)
|
|||||||
{
|
{
|
||||||
struct winlink *wl, *wl_loop;
|
struct winlink *wl, *wl_loop;
|
||||||
|
|
||||||
|
log_debug("%s: window is @%u", __func__, fs->w->id);
|
||||||
|
|
||||||
wl = NULL;
|
wl = NULL;
|
||||||
if (fs->s->curw != NULL && fs->s->curw->window == fs->w)
|
if (fs->s->curw != NULL && fs->s->curw->window == fs->w)
|
||||||
wl = fs->s->curw;
|
wl = fs->s->curw;
|
||||||
@@ -389,7 +404,7 @@ cmd_find_get_window_with_session(struct cmd_find_state *fs, const char *window)
|
|||||||
return (-1);
|
return (-1);
|
||||||
fs->idx = s->curw->idx + n;
|
fs->idx = s->curw->idx + n;
|
||||||
} else {
|
} else {
|
||||||
if (n < s->curw->idx)
|
if (n > s->curw->idx)
|
||||||
return (-1);
|
return (-1);
|
||||||
fs->idx = s->curw->idx - n;
|
fs->idx = s->curw->idx - n;
|
||||||
}
|
}
|
||||||
@@ -436,15 +451,15 @@ cmd_find_get_window_with_session(struct cmd_find_state *fs, const char *window)
|
|||||||
if (window[0] != '+' && window[0] != '-') {
|
if (window[0] != '+' && window[0] != '-') {
|
||||||
idx = strtonum(window, 0, INT_MAX, &errstr);
|
idx = strtonum(window, 0, INT_MAX, &errstr);
|
||||||
if (errstr == NULL) {
|
if (errstr == NULL) {
|
||||||
if (fs->flags & CMD_FIND_WINDOW_INDEX) {
|
|
||||||
fs->idx = idx;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
fs->wl = winlink_find_by_index(&fs->s->windows, idx);
|
fs->wl = winlink_find_by_index(&fs->s->windows, idx);
|
||||||
if (fs->wl != NULL) {
|
if (fs->wl != NULL) {
|
||||||
fs->w = fs->wl->window;
|
fs->w = fs->wl->window;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
if (fs->flags & CMD_FIND_WINDOW_INDEX) {
|
||||||
|
fs->idx = idx;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,8 +602,6 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
|||||||
|
|
||||||
/* Try special characters. */
|
/* Try special characters. */
|
||||||
if (strcmp(pane, "!") == 0) {
|
if (strcmp(pane, "!") == 0) {
|
||||||
if (fs->w->last == NULL)
|
|
||||||
return (-1);
|
|
||||||
fs->wp = fs->w->last;
|
fs->wp = fs->w->last;
|
||||||
if (fs->wp == NULL)
|
if (fs->wp == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
@@ -703,11 +716,11 @@ cmd_find_copy_state(struct cmd_find_state *dst, struct cmd_find_state *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Log the result. */
|
/* Log the result. */
|
||||||
void
|
static void
|
||||||
cmd_find_log_state(const char *prefix, struct cmd_find_state *fs)
|
cmd_find_log_state(const char *prefix, struct cmd_find_state *fs)
|
||||||
{
|
{
|
||||||
if (fs->s != NULL)
|
if (fs->s != NULL)
|
||||||
log_debug("%s: s=$%u", prefix, fs->s->id);
|
log_debug("%s: s=$%u %s", prefix, fs->s->id, fs->s->name);
|
||||||
else
|
else
|
||||||
log_debug("%s: s=none", prefix);
|
log_debug("%s: s=none", prefix);
|
||||||
if (fs->wl != NULL) {
|
if (fs->wl != NULL) {
|
||||||
@@ -896,6 +909,9 @@ cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (wl != NULL) {
|
if (wl != NULL) {
|
||||||
|
log_debug("%s: session $%u has pane %%%u", __func__,
|
||||||
|
s->id, wp->id);
|
||||||
|
|
||||||
fs->s = s;
|
fs->s = s;
|
||||||
fs->wl = s->curw; /* use current session */
|
fs->wl = s->curw; /* use current session */
|
||||||
fs->w = fs->wl->window;
|
fs->w = fs->wl->window;
|
||||||
@@ -903,6 +919,9 @@ cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags)
|
|||||||
|
|
||||||
cmd_find_log_state(__func__, fs);
|
cmd_find_log_state(__func__, fs);
|
||||||
return (0);
|
return (0);
|
||||||
|
} else {
|
||||||
|
log_debug("%s: session $%u does not have pane %%%u",
|
||||||
|
__func__, s->id, wp->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -912,16 +931,12 @@ cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags)
|
|||||||
*/
|
*/
|
||||||
fs->w = wp->window;
|
fs->w = wp->window;
|
||||||
if (cmd_find_best_session_with_window(fs) != 0) {
|
if (cmd_find_best_session_with_window(fs) != 0) {
|
||||||
if (wp != NULL) {
|
/*
|
||||||
/*
|
* The window may have been destroyed but the pane
|
||||||
* The window may have been destroyed but the pane
|
* still on all_window_panes due to something else
|
||||||
* still on all_window_panes due to something else
|
* holding a reference.
|
||||||
* holding a reference.
|
*/
|
||||||
*/
|
goto unknown_pane;
|
||||||
goto unknown_pane;
|
|
||||||
}
|
|
||||||
cmd_find_clear_state(fs, 0);
|
|
||||||
return (-1);
|
|
||||||
}
|
}
|
||||||
fs->wl = fs->s->curw;
|
fs->wl = fs->s->curw;
|
||||||
fs->w = fs->wl->window;
|
fs->w = fs->wl->window;
|
||||||
@@ -1147,7 +1162,8 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
|||||||
/* This will fill in winlink and window. */
|
/* This will fill in winlink and window. */
|
||||||
if (cmd_find_get_window_with_session(fs, window) != 0)
|
if (cmd_find_get_window_with_session(fs, window) != 0)
|
||||||
goto no_window;
|
goto no_window;
|
||||||
fs->wp = fs->wl->window->active;
|
if (fs->wl != NULL) /* can be NULL if index only */
|
||||||
|
fs->wp = fs->wl->window->active;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1187,7 +1203,8 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
|||||||
/* This will fill in session, winlink and window. */
|
/* This will fill in session, winlink and window. */
|
||||||
if (cmd_find_get_window(fs, window, window_only) != 0)
|
if (cmd_find_get_window(fs, window, window_only) != 0)
|
||||||
goto no_window;
|
goto no_window;
|
||||||
fs->wp = fs->wl->window->active;
|
if (fs->wl != NULL) /* can be NULL if index only */
|
||||||
|
fs->wp = fs->wl->window->active;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,14 +73,6 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct session *s = item->target.s;
|
struct session *s = item->target.s;
|
||||||
struct winlink *wl = item->target.wl;
|
struct winlink *wl = item->target.wl;
|
||||||
struct window_pane *wp = item->target.wp;
|
struct window_pane *wp = item->target.wp;
|
||||||
const char *cwd;
|
|
||||||
|
|
||||||
if (item->client != NULL && item->client->session == NULL)
|
|
||||||
cwd = item->client->cwd;
|
|
||||||
else if (s != NULL)
|
|
||||||
cwd = s->cwd;
|
|
||||||
else
|
|
||||||
cwd = NULL;
|
|
||||||
|
|
||||||
shellcmd = format_single(item, args->argv[0], c, s, wl, wp);
|
shellcmd = format_single(item, args->argv[0], c, s, wl, wp);
|
||||||
if (args_has(args, 'F')) {
|
if (args_has(args, 'F')) {
|
||||||
@@ -128,8 +120,8 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cdata->item = NULL;
|
cdata->item = NULL;
|
||||||
memcpy(&cdata->mouse, &shared->mouse, sizeof cdata->mouse);
|
memcpy(&cdata->mouse, &shared->mouse, sizeof cdata->mouse);
|
||||||
|
|
||||||
job_run(shellcmd, s, cwd, NULL, cmd_if_shell_callback,
|
job_run(shellcmd, s, server_client_get_cwd(item->client, s), NULL,
|
||||||
cmd_if_shell_free, cdata);
|
cmd_if_shell_callback, cmd_if_shell_free, cdata, 0);
|
||||||
free(shellcmd);
|
free(shellcmd);
|
||||||
|
|
||||||
if (args_has(args, 'b'))
|
if (args_has(args, 'b'))
|
||||||
|
|||||||
@@ -47,9 +47,8 @@ cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct winlink *wl = item->target.wl;
|
struct winlink *wl = item->target.wl;
|
||||||
struct window_pane *loopwp, *tmpwp, *wp = item->target.wp;
|
struct window_pane *loopwp, *tmpwp, *wp = item->target.wp;
|
||||||
|
|
||||||
server_unzoom_window(wl->window);
|
|
||||||
|
|
||||||
if (args_has(self->args, 'a')) {
|
if (args_has(self->args, 'a')) {
|
||||||
|
server_unzoom_window(wl->window);
|
||||||
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
|
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
|
||||||
if (loopwp == wp)
|
if (loopwp == wp)
|
||||||
continue;
|
continue;
|
||||||
@@ -60,13 +59,6 @@ cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window_count_panes(wl->window) == 1) {
|
server_kill_pane(wp);
|
||||||
server_kill_window(wl->window);
|
|
||||||
recalculate_sizes();
|
|
||||||
} else {
|
|
||||||
layout_close_pane(wp);
|
|
||||||
window_remove_pane(wl->window, wp);
|
|
||||||
server_redraw_window(wl->window);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,10 +75,14 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
repeat = 0;
|
repeat = 0;
|
||||||
tablewidth = keywidth = 0;
|
tablewidth = keywidth = 0;
|
||||||
RB_FOREACH(table, key_tables, &key_tables) {
|
table = key_bindings_first_table ();
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0)
|
while (table != NULL) {
|
||||||
|
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||||
|
table = key_bindings_next_table(table);
|
||||||
continue;
|
continue;
|
||||||
RB_FOREACH(bd, key_bindings, &table->key_bindings) {
|
}
|
||||||
|
bd = key_bindings_first(table);
|
||||||
|
while (bd != NULL) {
|
||||||
key = key_string_lookup_key(bd->key);
|
key = key_string_lookup_key(bd->key);
|
||||||
|
|
||||||
if (bd->flags & KEY_BINDING_REPEAT)
|
if (bd->flags & KEY_BINDING_REPEAT)
|
||||||
@@ -90,13 +94,20 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
width = utf8_cstrwidth(key);
|
width = utf8_cstrwidth(key);
|
||||||
if (width > keywidth)
|
if (width > keywidth)
|
||||||
keywidth = width;
|
keywidth = width;
|
||||||
|
|
||||||
|
bd = key_bindings_next(table, bd);
|
||||||
}
|
}
|
||||||
|
table = key_bindings_next_table(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_FOREACH(table, key_tables, &key_tables) {
|
table = key_bindings_first_table ();
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0)
|
while (table != NULL) {
|
||||||
|
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||||
|
table = key_bindings_next_table(table);
|
||||||
continue;
|
continue;
|
||||||
RB_FOREACH(bd, key_bindings, &table->key_bindings) {
|
}
|
||||||
|
bd = key_bindings_first(table);
|
||||||
|
while (bd != NULL) {
|
||||||
key = key_string_lookup_key(bd->key);
|
key = key_string_lookup_key(bd->key);
|
||||||
|
|
||||||
if (!repeat)
|
if (!repeat)
|
||||||
@@ -122,7 +133,9 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
free(cp);
|
free(cp);
|
||||||
|
|
||||||
cmdq_print(item, "bind-key %s", tmp);
|
cmdq_print(item, "bind-key %s", tmp);
|
||||||
|
bd = key_bindings_next(table, bd);
|
||||||
}
|
}
|
||||||
|
table = key_bindings_next_table(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|||||||
@@ -56,10 +56,14 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
struct cmd_load_buffer_data *cdata;
|
struct cmd_load_buffer_data *cdata;
|
||||||
struct client *c = item->client;
|
struct client *c = cmd_find_client(item, NULL, 1);
|
||||||
|
struct session *s = item->target.s;
|
||||||
|
struct winlink *wl = item->target.wl;
|
||||||
|
struct window_pane *wp = item->target.wp;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
const char *path, *bufname;
|
const char *bufname;
|
||||||
char *pdata, *new_pdata, *cause, *file;
|
char *pdata = NULL, *new_pdata, *cause;
|
||||||
|
char *path, *file;
|
||||||
size_t psize;
|
size_t psize;
|
||||||
int ch, error;
|
int ch, error;
|
||||||
|
|
||||||
@@ -67,8 +71,11 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (args_has(args, 'b'))
|
if (args_has(args, 'b'))
|
||||||
bufname = args_get(args, 'b');
|
bufname = args_get(args, 'b');
|
||||||
|
|
||||||
path = args->argv[0];
|
path = format_single(item, args->argv[0], c, s, wl, wp);
|
||||||
if (strcmp(path, "-") == 0) {
|
if (strcmp(path, "-") == 0) {
|
||||||
|
free(path);
|
||||||
|
c = item->client;
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
cdata = xcalloc(1, sizeof *cdata);
|
||||||
cdata->item = item;
|
cdata->item = item;
|
||||||
|
|
||||||
@@ -78,7 +85,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
error = server_set_stdin_callback(c, cmd_load_buffer_callback,
|
error = server_set_stdin_callback(c, cmd_load_buffer_callback,
|
||||||
cdata, &cause);
|
cdata, &cause);
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
cmdq_error(item, "%s: %s", path, cause);
|
cmdq_error(item, "-: %s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
@@ -86,11 +93,12 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
file = server_client_get_path(c, path);
|
file = server_client_get_path(c, path);
|
||||||
|
free(path);
|
||||||
|
|
||||||
f = fopen(file, "rb");
|
f = fopen(file, "rb");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
cmdq_error(item, "%s: %s", file, strerror(errno));
|
cmdq_error(item, "%s: %s", file, strerror(errno));
|
||||||
free(file);
|
goto error;
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pdata = NULL;
|
pdata = NULL;
|
||||||
|
|||||||
@@ -73,14 +73,15 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct environ *env;
|
struct environ *env;
|
||||||
struct termios tio, *tiop;
|
struct termios tio, *tiop;
|
||||||
struct session_group *sg;
|
struct session_group *sg;
|
||||||
const char *newname, *errstr, *template, *group, *prefix;
|
const char *errstr, *template, *group, *prefix;
|
||||||
const char *path, *cmd, *cwd;
|
const char *path, *cmd, *tmp;
|
||||||
char **argv, *cause, *cp, *to_free = NULL;
|
char **argv, *cause, *cp, *newname, *cwd = NULL;
|
||||||
int detached, already_attached, idx, argc;
|
int detached, already_attached, idx, argc;
|
||||||
int is_control = 0;
|
int is_control = 0;
|
||||||
u_int sx, sy;
|
u_int sx, sy;
|
||||||
struct environ_entry *envent;
|
struct environ_entry *envent;
|
||||||
struct cmd_find_state fs;
|
struct cmd_find_state fs;
|
||||||
|
enum cmd_retval retval;
|
||||||
|
|
||||||
if (self->entry == &cmd_has_session_entry) {
|
if (self->entry == &cmd_has_session_entry) {
|
||||||
/*
|
/*
|
||||||
@@ -95,20 +96,24 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
newname = args_get(args, 's');
|
newname = NULL;
|
||||||
if (newname != NULL) {
|
if (args_has(args, 's')) {
|
||||||
|
newname = format_single(item, args_get(args, 's'), c, NULL,
|
||||||
|
NULL, NULL);
|
||||||
if (!session_check_name(newname)) {
|
if (!session_check_name(newname)) {
|
||||||
cmdq_error(item, "bad session name: %s", newname);
|
cmdq_error(item, "bad session name: %s", newname);
|
||||||
return (CMD_RETURN_ERROR);
|
goto error;
|
||||||
}
|
}
|
||||||
if ((as = session_find(newname)) != NULL) {
|
if ((as = session_find(newname)) != NULL) {
|
||||||
if (args_has(args, 'A')) {
|
if (args_has(args, 'A')) {
|
||||||
return (cmd_attach_session(item,
|
retval = cmd_attach_session(item,
|
||||||
newname, args_has(args, 'D'),
|
newname, args_has(args, 'D'),
|
||||||
0, NULL, args_has(args, 'E')));
|
0, NULL, args_has(args, 'E'));
|
||||||
|
free(newname);
|
||||||
|
return (retval);
|
||||||
}
|
}
|
||||||
cmdq_error(item, "duplicate session: %s", newname);
|
cmdq_error(item, "duplicate session: %s", newname);
|
||||||
return (CMD_RETURN_ERROR);
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,14 +154,10 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
already_attached = 1;
|
already_attached = 1;
|
||||||
|
|
||||||
/* Get the new session working directory. */
|
/* Get the new session working directory. */
|
||||||
if (args_has(args, 'c')) {
|
if ((tmp = args_get(args, 'c')) != NULL)
|
||||||
cwd = args_get(args, 'c');
|
cwd = format_single(item, tmp, c, NULL, NULL, NULL);
|
||||||
to_free = format_single(item, cwd, c, NULL, NULL, NULL);
|
|
||||||
cwd = to_free;
|
|
||||||
} else if (c != NULL && c->session == NULL && c->cwd != NULL)
|
|
||||||
cwd = c->cwd;
|
|
||||||
else
|
else
|
||||||
cwd = ".";
|
cwd = xstrdup(server_client_get_cwd(c, NULL));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this is a new client, check for nesting and save the termios
|
* If this is a new client, check for nesting and save the termios
|
||||||
@@ -201,17 +202,29 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
sy = 24;
|
sy = 24;
|
||||||
}
|
}
|
||||||
if ((is_control || detached) && args_has(args, 'x')) {
|
if ((is_control || detached) && args_has(args, 'x')) {
|
||||||
sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr);
|
tmp = args_get(args, 'x');
|
||||||
if (errstr != NULL) {
|
if (strcmp(tmp, "-") == 0) {
|
||||||
cmdq_error(item, "width %s", errstr);
|
if (c != NULL)
|
||||||
goto error;
|
sx = c->tty.sx;
|
||||||
|
} else {
|
||||||
|
sx = strtonum(tmp, 1, USHRT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
cmdq_error(item, "width %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((is_control || detached) && args_has(args, 'y')) {
|
if ((is_control || detached) && args_has(args, 'y')) {
|
||||||
sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr);
|
tmp = args_get(args, 'y');
|
||||||
if (errstr != NULL) {
|
if (strcmp(tmp, "-") == 0) {
|
||||||
cmdq_error(item, "height %s", errstr);
|
if (c != NULL)
|
||||||
goto error;
|
sy = c->tty.sy;
|
||||||
|
} else {
|
||||||
|
sy = strtonum(tmp, 1, USHRT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
cmdq_error(item, "height %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sx == 0)
|
if (sx == 0)
|
||||||
@@ -261,10 +274,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the initial window name if one given. */
|
/* Set the initial window name if one given. */
|
||||||
if (argc >= 0 && args_has(args, 'n')) {
|
if (argc >= 0 && (tmp = args_get(args, 'n')) != NULL) {
|
||||||
|
cp = format_single(item, tmp, c, s, NULL, NULL);
|
||||||
w = s->curw->window;
|
w = s->curw->window;
|
||||||
window_set_name(w, args_get(args, 'n'));
|
window_set_name(w, cp);
|
||||||
options_set_number(w->options, "automatic-rename", 0);
|
options_set_number(w->options, "automatic-rename", 0);
|
||||||
|
free(cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -331,10 +346,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cmd_find_from_session(&fs, s, 0);
|
cmd_find_from_session(&fs, s, 0);
|
||||||
hooks_insert(s->hooks, item, &fs, "after-new-session");
|
hooks_insert(s->hooks, item, &fs, "after-new-session");
|
||||||
|
|
||||||
free(to_free);
|
free(cwd);
|
||||||
|
free(newname);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(to_free);
|
free(cwd);
|
||||||
|
free(newname);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,13 +57,13 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct winlink *wl = item->target.wl;
|
struct winlink *wl = item->target.wl;
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
struct client *c = cmd_find_client(item, NULL, 1);
|
||||||
int idx = item->target.idx;
|
int idx = item->target.idx;
|
||||||
const char *cmd, *path, *template, *cwd;
|
const char *cmd, *path, *template, *tmp;
|
||||||
char **argv, *cause, *cp, *to_free = NULL;
|
char **argv, *cause, *cp, *cwd, *name;
|
||||||
int argc, detached;
|
int argc, detached;
|
||||||
struct environ_entry *envent;
|
struct environ_entry *envent;
|
||||||
struct cmd_find_state fs;
|
struct cmd_find_state fs;
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
if (args_has(args, 'a') && wl != NULL) {
|
||||||
if ((idx = winlink_shuffle_up(s, wl)) == -1) {
|
if ((idx = winlink_shuffle_up(s, wl)) == -1) {
|
||||||
cmdq_error(item, "no free window indexes");
|
cmdq_error(item, "no free window indexes");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -93,16 +93,16 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (envent != NULL)
|
if (envent != NULL)
|
||||||
path = envent->value;
|
path = envent->value;
|
||||||
|
|
||||||
if (args_has(args, 'c')) {
|
if ((tmp = args_get(args, 'c')) != NULL)
|
||||||
cwd = args_get(args, 'c');
|
cwd = format_single(item, tmp, c, s, NULL, NULL);
|
||||||
to_free = format_single(item, cwd, c, s, NULL, NULL);
|
|
||||||
cwd = to_free;
|
|
||||||
} else if (item->client != NULL && item->client->session == NULL)
|
|
||||||
cwd = item->client->cwd;
|
|
||||||
else
|
else
|
||||||
cwd = s->cwd;
|
cwd = xstrdup(server_client_get_cwd(item->client, s));
|
||||||
|
|
||||||
|
if ((tmp = args_get(args, 'n')) != NULL)
|
||||||
|
name = format_single(item, tmp, c, s, NULL, NULL);
|
||||||
|
else
|
||||||
|
name = NULL;
|
||||||
|
|
||||||
wl = NULL;
|
|
||||||
if (idx != -1)
|
if (idx != -1)
|
||||||
wl = winlink_find_by_index(&s->windows, idx);
|
wl = winlink_find_by_index(&s->windows, idx);
|
||||||
if (wl != NULL && args_has(args, 'k')) {
|
if (wl != NULL && args_has(args, 'k')) {
|
||||||
@@ -124,7 +124,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
idx = -1 - options_get_number(s->options, "base-index");
|
idx = -1 - options_get_number(s->options, "base-index");
|
||||||
wl = session_new(s, args_get(args, 'n'), argc, argv, path, cwd, idx,
|
wl = session_new(s, name, argc, argv, path, cwd, idx,
|
||||||
&cause);
|
&cause);
|
||||||
if (wl == NULL) {
|
if (wl == NULL) {
|
||||||
cmdq_error(item, "create window failed: %s", cause);
|
cmdq_error(item, "create window failed: %s", cause);
|
||||||
@@ -149,10 +149,12 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cmd_find_from_winlink(&fs, wl, 0);
|
cmd_find_from_winlink(&fs, wl, 0);
|
||||||
hooks_insert(s->hooks, item, &fs, "after-new-window");
|
hooks_insert(s->hooks, item, &fs, "after-new-window");
|
||||||
|
|
||||||
free(to_free);
|
free(name);
|
||||||
|
free(cwd);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(to_free);
|
free(name);
|
||||||
|
free(cwd);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmdq_item *);
|
static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmdq_item *);
|
||||||
|
|
||||||
|
static void cmd_pipe_pane_read_callback(struct bufferevent *, void *);
|
||||||
static void cmd_pipe_pane_write_callback(struct bufferevent *, void *);
|
static void cmd_pipe_pane_write_callback(struct bufferevent *, void *);
|
||||||
static void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
static void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
||||||
|
|
||||||
@@ -42,8 +43,8 @@ const struct cmd_entry cmd_pipe_pane_entry = {
|
|||||||
.name = "pipe-pane",
|
.name = "pipe-pane",
|
||||||
.alias = "pipep",
|
.alias = "pipep",
|
||||||
|
|
||||||
.args = { "ot:", 0, 1 },
|
.args = { "IOot:", 0, 1 },
|
||||||
.usage = "[-o] " CMD_TARGET_PANE_USAGE " [command]",
|
.usage = "[-IOo] " CMD_TARGET_PANE_USAGE " [command]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct session *s = item->target.s;
|
struct session *s = item->target.s;
|
||||||
struct winlink *wl = item->target.wl;
|
struct winlink *wl = item->target.wl;
|
||||||
char *cmd;
|
char *cmd;
|
||||||
int old_fd, pipe_fd[2], null_fd;
|
int old_fd, pipe_fd[2], null_fd, in, out;
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
sigset_t set, oldset;
|
sigset_t set, oldset;
|
||||||
|
|
||||||
@@ -90,6 +91,15 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (args_has(self->args, 'o') && old_fd != -1)
|
if (args_has(self->args, 'o') && old_fd != -1)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
|
/* What do we want to do? Neither -I or -O is -O. */
|
||||||
|
if (args_has(self->args, 'I')) {
|
||||||
|
in = 1;
|
||||||
|
out = args_has(self->args, 'O');
|
||||||
|
} else {
|
||||||
|
in = 0;
|
||||||
|
out = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Open the new pipe. */
|
/* Open the new pipe. */
|
||||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
||||||
cmdq_error(item, "socketpair error: %s", strerror(errno));
|
cmdq_error(item, "socketpair error: %s", strerror(errno));
|
||||||
@@ -118,19 +128,25 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||||
close(pipe_fd[0]);
|
close(pipe_fd[0]);
|
||||||
|
|
||||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
|
||||||
_exit(1);
|
|
||||||
if (pipe_fd[1] != STDIN_FILENO)
|
|
||||||
close(pipe_fd[1]);
|
|
||||||
|
|
||||||
null_fd = open(_PATH_DEVNULL, O_WRONLY, 0);
|
null_fd = open(_PATH_DEVNULL, O_WRONLY, 0);
|
||||||
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
if (out) {
|
||||||
_exit(1);
|
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
||||||
|
_exit(1);
|
||||||
|
} else {
|
||||||
|
if (dup2(null_fd, STDIN_FILENO) == -1)
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
if (in) {
|
||||||
|
if (dup2(pipe_fd[1], STDOUT_FILENO) == -1)
|
||||||
|
_exit(1);
|
||||||
|
if (pipe_fd[1] != STDOUT_FILENO)
|
||||||
|
close(pipe_fd[1]);
|
||||||
|
} else {
|
||||||
|
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
if (dup2(null_fd, STDERR_FILENO) == -1)
|
if (dup2(null_fd, STDERR_FILENO) == -1)
|
||||||
_exit(1);
|
_exit(1);
|
||||||
if (null_fd != STDOUT_FILENO && null_fd != STDERR_FILENO)
|
|
||||||
close(null_fd);
|
|
||||||
|
|
||||||
closefrom(STDERR_FILENO + 1);
|
closefrom(STDERR_FILENO + 1);
|
||||||
|
|
||||||
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
|
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
|
||||||
@@ -143,24 +159,46 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
wp->pipe_fd = pipe_fd[0];
|
wp->pipe_fd = pipe_fd[0];
|
||||||
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
|
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
|
||||||
|
|
||||||
wp->pipe_event = bufferevent_new(wp->pipe_fd, NULL,
|
|
||||||
cmd_pipe_pane_write_callback, cmd_pipe_pane_error_callback,
|
|
||||||
wp);
|
|
||||||
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
|
||||||
|
|
||||||
setblocking(wp->pipe_fd, 0);
|
setblocking(wp->pipe_fd, 0);
|
||||||
|
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
||||||
|
cmd_pipe_pane_read_callback,
|
||||||
|
cmd_pipe_pane_write_callback,
|
||||||
|
cmd_pipe_pane_error_callback,
|
||||||
|
wp);
|
||||||
|
if (out)
|
||||||
|
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
||||||
|
if (in)
|
||||||
|
bufferevent_enable(wp->pipe_event, EV_READ);
|
||||||
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cmd_pipe_pane_read_callback(__unused struct bufferevent *bufev, void *data)
|
||||||
|
{
|
||||||
|
struct window_pane *wp = data;
|
||||||
|
struct evbuffer *evb = wp->pipe_event->input;
|
||||||
|
size_t available;
|
||||||
|
|
||||||
|
available = EVBUFFER_LENGTH(evb);
|
||||||
|
log_debug("%%%u pipe read %zu", wp->id, available);
|
||||||
|
|
||||||
|
bufferevent_write(wp->event, EVBUFFER_DATA(evb), available);
|
||||||
|
evbuffer_drain(evb, available);
|
||||||
|
|
||||||
|
if (window_pane_destroy_ready(wp))
|
||||||
|
server_destroy_pane(wp, 1);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cmd_pipe_pane_write_callback(__unused struct bufferevent *bufev, void *data)
|
cmd_pipe_pane_write_callback(__unused struct bufferevent *bufev, void *data)
|
||||||
{
|
{
|
||||||
struct window_pane *wp = data;
|
struct window_pane *wp = data;
|
||||||
|
|
||||||
log_debug("%%%u pipe empty", wp->id);
|
log_debug("%%%u pipe empty", wp->id);
|
||||||
|
|
||||||
if (window_pane_destroy_ready(wp))
|
if (window_pane_destroy_ready(wp))
|
||||||
server_destroy_pane(wp, 1);
|
server_destroy_pane(wp, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,26 +46,31 @@ const struct cmd_entry cmd_rename_session_entry = {
|
|||||||
static enum cmd_retval
|
static enum cmd_retval
|
||||||
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
struct session *s = item->target.s;
|
struct client *c = cmd_find_client(item, NULL, 1);
|
||||||
const char *newname;
|
struct session *s = item->target.s;
|
||||||
|
char *newname;
|
||||||
|
|
||||||
newname = args->argv[0];
|
newname = format_single(item, args->argv[0], c, s, NULL, NULL);
|
||||||
if (strcmp(newname, s->name) == 0)
|
if (strcmp(newname, s->name) == 0) {
|
||||||
|
free(newname);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
if (!session_check_name(newname)) {
|
if (!session_check_name(newname)) {
|
||||||
cmdq_error(item, "bad session name: %s", newname);
|
cmdq_error(item, "bad session name: %s", newname);
|
||||||
|
free(newname);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
if (session_find(newname) != NULL) {
|
if (session_find(newname) != NULL) {
|
||||||
cmdq_error(item, "duplicate session: %s", newname);
|
cmdq_error(item, "duplicate session: %s", newname);
|
||||||
|
free(newname);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_REMOVE(sessions, &sessions, s);
|
RB_REMOVE(sessions, &sessions, s);
|
||||||
free(s->name);
|
free(s->name);
|
||||||
s->name = xstrdup(newname);
|
s->name = newname;
|
||||||
RB_INSERT(sessions, &sessions, s);
|
RB_INSERT(sessions, &sessions, s);
|
||||||
|
|
||||||
server_status_session(s);
|
server_status_session(s);
|
||||||
|
|||||||
@@ -46,12 +46,17 @@ static enum cmd_retval
|
|||||||
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
|
struct client *c = cmd_find_client(item, NULL, 1);
|
||||||
|
struct session *s = item->target.s;
|
||||||
struct winlink *wl = item->target.wl;
|
struct winlink *wl = item->target.wl;
|
||||||
|
char *newname;
|
||||||
|
|
||||||
window_set_name(wl->window, args->argv[0]);
|
newname = format_single(item, args->argv[0], c, s, wl, NULL);
|
||||||
|
window_set_name(wl->window, newname);
|
||||||
options_set_number(wl->window->options, "automatic-rename", 0);
|
options_set_number(wl->window->options, "automatic-rename", 0);
|
||||||
|
|
||||||
server_status_window(wl->window);
|
server_status_window(wl->window);
|
||||||
|
free(newname);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,14 +129,21 @@ static void
|
|||||||
cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
|
cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
|
||||||
{
|
{
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct window_pane *loop, *wp_x, *wp_y;
|
struct window *w;
|
||||||
u_int y, ly, x, lx, sx, sy, ex, ey;
|
u_int y, ly, x, lx;
|
||||||
|
static const int offsets[][2] = {
|
||||||
|
{ 0, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
|
||||||
|
};
|
||||||
|
struct layout_cell *cells[nitems(offsets)], *lc;
|
||||||
|
u_int ncells = 0, i, j, resizes = 0;
|
||||||
|
enum layout_type type;
|
||||||
|
|
||||||
wl = cmd_mouse_window(m, NULL);
|
wl = cmd_mouse_window(m, NULL);
|
||||||
if (wl == NULL) {
|
if (wl == NULL) {
|
||||||
c->tty.mouse_drag_update = NULL;
|
c->tty.mouse_drag_update = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
y = m->y; x = m->x;
|
y = m->y; x = m->x;
|
||||||
if (m->statusat == 0 && y > 0)
|
if (m->statusat == 0 && y > 0)
|
||||||
@@ -149,37 +156,37 @@ cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
|
|||||||
else if (m->statusat > 0 && ly >= (u_int)m->statusat)
|
else if (m->statusat > 0 && ly >= (u_int)m->statusat)
|
||||||
ly = m->statusat - 1;
|
ly = m->statusat - 1;
|
||||||
|
|
||||||
wp_x = wp_y = NULL;
|
for (i = 0; i < nitems(cells); i++) {
|
||||||
TAILQ_FOREACH(loop, &wl->window->panes, entry) {
|
lc = layout_search_by_border(w->layout_root, lx + offsets[i][0],
|
||||||
if (!window_pane_visible(loop))
|
ly + offsets[i][1]);
|
||||||
|
if (lc == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sx = loop->xoff;
|
for (j = 0; j < ncells; j++) {
|
||||||
if (sx != 0)
|
if (cells[j] == lc) {
|
||||||
sx--;
|
lc = NULL;
|
||||||
ex = loop->xoff + loop->sx;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lc == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
sy = loop->yoff;
|
cells[ncells] = lc;
|
||||||
if (sy != 0)
|
ncells++;
|
||||||
sy--;
|
|
||||||
ey = loop->yoff + loop->sy;
|
|
||||||
|
|
||||||
if ((lx == sx || lx == ex) &&
|
|
||||||
(ly >= sy && ly <= ey) &&
|
|
||||||
(wp_x == NULL || loop->sy > wp_x->sy))
|
|
||||||
wp_x = loop;
|
|
||||||
if ((ly == sy || ly == ey) &&
|
|
||||||
(lx >= sx && lx <= ex) &&
|
|
||||||
(wp_y == NULL || loop->sx > wp_y->sx))
|
|
||||||
wp_y = loop;
|
|
||||||
}
|
}
|
||||||
if (wp_x == NULL && wp_y == NULL) {
|
if (ncells == 0)
|
||||||
c->tty.mouse_drag_update = NULL;
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < ncells; i++) {
|
||||||
|
type = cells[i]->parent->type;
|
||||||
|
if (y != ly && type == LAYOUT_TOPBOTTOM) {
|
||||||
|
layout_resize_layout(w, cells[i], type, y - ly, 0);
|
||||||
|
resizes++;
|
||||||
|
} else if (x != lx && type == LAYOUT_LEFTRIGHT) {
|
||||||
|
layout_resize_layout(w, cells[i], type, x - lx, 0);
|
||||||
|
resizes++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (wp_x != NULL)
|
if (resizes != 0)
|
||||||
layout_resize_pane(wp_x, LAYOUT_LEFTRIGHT, x - lx, 0);
|
server_redraw_window(w);
|
||||||
if (wp_y != NULL)
|
|
||||||
layout_resize_pane(wp_y, LAYOUT_TOPBOTTOM, y - ly, 0);
|
|
||||||
server_redraw_window(wl->window);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,14 +90,6 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct session *s = item->target.s;
|
struct session *s = item->target.s;
|
||||||
struct winlink *wl = item->target.wl;
|
struct winlink *wl = item->target.wl;
|
||||||
struct window_pane *wp = item->target.wp;
|
struct window_pane *wp = item->target.wp;
|
||||||
const char *cwd;
|
|
||||||
|
|
||||||
if (item->client != NULL && item->client->session == NULL)
|
|
||||||
cwd = item->client->cwd;
|
|
||||||
else if (s != NULL)
|
|
||||||
cwd = s->cwd;
|
|
||||||
else
|
|
||||||
cwd = NULL;
|
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
cdata = xcalloc(1, sizeof *cdata);
|
||||||
cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp);
|
cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp);
|
||||||
@@ -110,8 +102,8 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (!args_has(args, 'b'))
|
if (!args_has(args, 'b'))
|
||||||
cdata->item = item;
|
cdata->item = item;
|
||||||
|
|
||||||
job_run(cdata->cmd, s, cwd, NULL, cmd_run_shell_callback,
|
job_run(cdata->cmd, s, server_client_get_cwd(item->client, s), NULL,
|
||||||
cmd_run_shell_free, cdata);
|
cmd_run_shell_callback, cmd_run_shell_free, cdata, 0);
|
||||||
|
|
||||||
if (args_has(args, 'b'))
|
if (args_has(args, 'b'))
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|||||||
@@ -59,11 +59,13 @@ static enum cmd_retval
|
|||||||
cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
struct client *c = item->client;
|
struct client *c = cmd_find_client(item, NULL, 1);
|
||||||
|
struct session *s = item->target.s;
|
||||||
|
struct winlink *wl = item->target.wl;
|
||||||
|
struct window_pane *wp = item->target.wp;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
const char *path, *bufname, *bufdata, *start, *end;
|
const char *bufname, *bufdata, *start, *end, *flags;
|
||||||
const char *flags;
|
char *msg, *path, *file;
|
||||||
char *msg, *file;
|
|
||||||
size_t size, used, msglen, bufsize;
|
size_t size, used, msglen, bufsize;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
@@ -83,10 +85,12 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
bufdata = paste_buffer_data(pb, &bufsize);
|
bufdata = paste_buffer_data(pb, &bufsize);
|
||||||
|
|
||||||
if (self->entry == &cmd_show_buffer_entry)
|
if (self->entry == &cmd_show_buffer_entry)
|
||||||
path = "-";
|
path = xstrdup("-");
|
||||||
else
|
else
|
||||||
path = args->argv[0];
|
path = format_single(item, args->argv[0], c, s, wl, wp);
|
||||||
if (strcmp(path, "-") == 0) {
|
if (strcmp(path, "-") == 0) {
|
||||||
|
free(path);
|
||||||
|
c = item->client;
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
cmdq_error(item, "can't write to stdout");
|
cmdq_error(item, "can't write to stdout");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -101,6 +105,8 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
flags = "ab";
|
flags = "ab";
|
||||||
|
|
||||||
file = server_client_get_path(c, path);
|
file = server_client_get_path(c, path);
|
||||||
|
free(path);
|
||||||
|
|
||||||
f = fopen(file, flags);
|
f = fopen(file, flags);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
cmdq_error(item, "%s: %s", file, strerror(errno));
|
cmdq_error(item, "%s: %s", file, strerror(errno));
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ const struct cmd_entry cmd_select_layout_entry = {
|
|||||||
.name = "select-layout",
|
.name = "select-layout",
|
||||||
.alias = "selectl",
|
.alias = "selectl",
|
||||||
|
|
||||||
.args = { "nopt:", 0, 1 },
|
.args = { "Enopt:", 0, 1 },
|
||||||
.usage = "[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
.usage = "[-Enop] " CMD_TARGET_PANE_USAGE " [layout-name]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
.flags = CMD_AFTERHOOK,
|
||||||
.exec = cmd_select_layout_exec
|
.exec = cmd_select_layout_exec
|
||||||
@@ -71,14 +71,14 @@ const struct cmd_entry cmd_previous_layout_entry = {
|
|||||||
static enum cmd_retval
|
static enum cmd_retval
|
||||||
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
struct winlink *wl = item->target.wl;
|
struct winlink *wl = item->target.wl;
|
||||||
struct window *w;
|
struct window *w = wl->window;
|
||||||
const char *layoutname;
|
struct window_pane *wp = item->target.wp;
|
||||||
char *oldlayout;
|
const char *layoutname;
|
||||||
int next, previous, layout;
|
char *oldlayout;
|
||||||
|
int next, previous, layout;
|
||||||
|
|
||||||
w = wl->window;
|
|
||||||
server_unzoom_window(w);
|
server_unzoom_window(w);
|
||||||
|
|
||||||
next = self->entry == &cmd_next_layout_entry;
|
next = self->entry == &cmd_next_layout_entry;
|
||||||
@@ -99,6 +99,11 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
goto changed;
|
goto changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args_has(args, 'E')) {
|
||||||
|
layout_spread_out(wp);
|
||||||
|
goto changed;
|
||||||
|
}
|
||||||
|
|
||||||
if (!args_has(args, 'o')) {
|
if (!args_has(args, 'o')) {
|
||||||
if (args->argc == 0)
|
if (args->argc == 0)
|
||||||
layout = w->lastlayout;
|
layout = w->lastlayout;
|
||||||
@@ -131,6 +136,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
changed:
|
changed:
|
||||||
free(oldlayout);
|
free(oldlayout);
|
||||||
server_redraw_window(w);
|
server_redraw_window(w);
|
||||||
|
notify_window("window-layout-changed", w);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -57,14 +59,21 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *current = &item->shared->current;
|
struct cmd_find_state *current = &item->shared->current;
|
||||||
|
struct client *c = cmd_find_client(item, NULL, 1);
|
||||||
struct winlink *wl = item->target.wl;
|
struct winlink *wl = item->target.wl;
|
||||||
struct window *w = wl->window;
|
struct window *w = wl->window;
|
||||||
struct session *s = item->target.s;
|
struct session *s = item->target.s;
|
||||||
struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
|
struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
|
||||||
|
char *pane_title;
|
||||||
const char *style;
|
const char *style;
|
||||||
|
|
||||||
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
||||||
lastwp = w->last;
|
lastwp = w->last;
|
||||||
|
if (lastwp == NULL && window_count_panes(w) == 2) {
|
||||||
|
lastwp = TAILQ_PREV(w->active, window_panes, entry);
|
||||||
|
if (lastwp == NULL)
|
||||||
|
lastwp = TAILQ_NEXT(w->active, entry);
|
||||||
|
}
|
||||||
if (lastwp == NULL) {
|
if (lastwp == NULL) {
|
||||||
cmdq_error(item, "no last pane");
|
cmdq_error(item, "no last pane");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -148,8 +157,12 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(self->args, 'T')) {
|
if (args_has(self->args, 'T')) {
|
||||||
screen_set_title(&wp->base, args_get(self->args, 'T'));
|
pane_title = format_single(item, args_get(self->args, 'T'),
|
||||||
server_status_window(wp->window);
|
c, s, wl, wp);
|
||||||
|
screen_set_title(&wp->base, pane_title);
|
||||||
|
server_status_window(wp->window);
|
||||||
|
free(pane_title);
|
||||||
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wp == w->active)
|
if (wp == w->active)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key)
|
|||||||
struct window_pane *wp = item->target.wp;
|
struct window_pane *wp = item->target.wp;
|
||||||
struct session *s = item->target.s;
|
struct session *s = item->target.s;
|
||||||
struct key_table *table;
|
struct key_table *table;
|
||||||
struct key_binding *bd, bd_find;
|
struct key_binding *bd;
|
||||||
|
|
||||||
if (wp->mode == NULL || wp->mode->key_table == NULL) {
|
if (wp->mode == NULL || wp->mode->key_table == NULL) {
|
||||||
if (options_get_number(wp->window->options, "xterm-keys"))
|
if (options_get_number(wp->window->options, "xterm-keys"))
|
||||||
@@ -71,8 +71,7 @@ cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key)
|
|||||||
}
|
}
|
||||||
table = key_bindings_get_table(wp->mode->key_table(wp), 1);
|
table = key_bindings_get_table(wp->mode->key_table(wp), 1);
|
||||||
|
|
||||||
bd_find.key = (key & ~KEYC_XTERM);
|
bd = key_bindings_get(table, key & ~KEYC_XTERM);
|
||||||
bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find);
|
|
||||||
if (bd != NULL) {
|
if (bd != NULL) {
|
||||||
table->references++;
|
table->references++;
|
||||||
key_bindings_dispatch(bd, item, c, NULL, &item->target);
|
key_bindings_dispatch(bd, item, c, NULL, &item->target);
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ const struct cmd_entry cmd_set_hook_entry = {
|
|||||||
.name = "set-hook",
|
.name = "set-hook",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "gt:u", 1, 2 },
|
.args = { "gRt:u", 1, 2 },
|
||||||
.usage = "[-gu] " CMD_TARGET_SESSION_USAGE " hook-name [command]",
|
.usage = "[-gRu] " CMD_TARGET_SESSION_USAGE " hook-name [command]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||||
|
|
||||||
@@ -101,18 +101,21 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
else
|
else
|
||||||
cmd = args->argv[1];
|
cmd = args->argv[1];
|
||||||
|
|
||||||
|
if (cmd != NULL && (args_has(args, 'R') || args_has(args, 'u'))) {
|
||||||
|
cmdq_error(item, "no command allowed");
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
if (args_has(args, 'R')) {
|
||||||
|
notify_hook(item, name);
|
||||||
|
return (CMD_RETURN_NORMAL);
|
||||||
|
}
|
||||||
if (args_has(args, 'u')) {
|
if (args_has(args, 'u')) {
|
||||||
if (cmd != NULL) {
|
|
||||||
cmdq_error(item, "command passed to unset hook: %s",
|
|
||||||
name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
hooks_remove(hooks, name);
|
hooks_remove(hooks, name);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd == NULL) {
|
if (cmd == NULL) {
|
||||||
cmdq_error(item, "no command to set hook: %s", name);
|
cmdq_error(item, "no command given");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||||
|
|||||||
@@ -192,7 +192,9 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (o == NULL)
|
if (o == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
if (idx == -1) {
|
if (idx == -1) {
|
||||||
if (oo == global_options ||
|
if (*name == '@')
|
||||||
|
options_remove(o);
|
||||||
|
else if (oo == global_options ||
|
||||||
oo == global_s_options ||
|
oo == global_s_options ||
|
||||||
oo == global_w_options)
|
oo == global_w_options)
|
||||||
options_default(oo, options_table_entry(o));
|
options_default(oo, options_table_entry(o));
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (*path == '/')
|
if (*path == '/')
|
||||||
pattern = xstrdup(path);
|
pattern = xstrdup(path);
|
||||||
else {
|
else {
|
||||||
utf8_stravis(&tmp, server_client_get_cwd(c), VIS_GLOB);
|
utf8_stravis(&tmp, server_client_get_cwd(c, NULL), VIS_GLOB);
|
||||||
xasprintf(&pattern, "%s/%s", tmp, path);
|
xasprintf(&pattern, "%s/%s", tmp, path);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,10 +60,10 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct window *w = wl->window;
|
struct window *w = wl->window;
|
||||||
struct window_pane *wp = item->target.wp, *new_wp = NULL;
|
struct window_pane *wp = item->target.wp, *new_wp = NULL;
|
||||||
struct environ *env;
|
struct environ *env;
|
||||||
const char *cmd, *path, *shell, *template, *cwd;
|
const char *cmd, *path, *shell, *template, *tmp;
|
||||||
char **argv, *cause, *new_cause, *cp, *to_free = NULL;
|
char **argv, *cause, *new_cause, *cp, *cwd;
|
||||||
u_int hlimit;
|
u_int hlimit;
|
||||||
int argc, size, percentage;
|
int argc, size, percentage, before;
|
||||||
enum layout_type type;
|
enum layout_type type;
|
||||||
struct layout_cell *lc;
|
struct layout_cell *lc;
|
||||||
struct environ_entry *envent;
|
struct environ_entry *envent;
|
||||||
@@ -85,18 +85,15 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
argv = args->argv;
|
argv = args->argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'c')) {
|
if ((tmp = args_get(args, 'c')) != NULL)
|
||||||
cwd = args_get(args, 'c');
|
cwd = format_single(item, tmp, c, s, NULL, NULL);
|
||||||
to_free = format_single(item, cwd, c, s, NULL, NULL);
|
|
||||||
cwd = to_free;
|
|
||||||
} else if (item->client != NULL && item->client->session == NULL)
|
|
||||||
cwd = item->client->cwd;
|
|
||||||
else
|
else
|
||||||
cwd = s->cwd;
|
cwd = xstrdup(server_client_get_cwd(item->client, s));
|
||||||
|
|
||||||
type = LAYOUT_TOPBOTTOM;
|
type = LAYOUT_TOPBOTTOM;
|
||||||
if (args_has(args, 'h'))
|
if (args_has(args, 'h'))
|
||||||
type = LAYOUT_LEFTRIGHT;
|
type = LAYOUT_LEFTRIGHT;
|
||||||
|
before = args_has(args, 'b');
|
||||||
|
|
||||||
size = -1;
|
size = -1;
|
||||||
if (args_has(args, 'l')) {
|
if (args_has(args, 'l')) {
|
||||||
@@ -126,13 +123,12 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (*shell == '\0' || areshell(shell))
|
if (*shell == '\0' || areshell(shell))
|
||||||
shell = _PATH_BSHELL;
|
shell = _PATH_BSHELL;
|
||||||
|
|
||||||
lc = layout_split_pane(wp, type, size, args_has(args, 'b'),
|
lc = layout_split_pane(wp, type, size, before, args_has(args, 'f'));
|
||||||
args_has(args, 'f'));
|
|
||||||
if (lc == NULL) {
|
if (lc == NULL) {
|
||||||
cause = xstrdup("pane too small");
|
cause = xstrdup("pane too small");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
new_wp = window_add_pane(w, wp, args_has(args, 'b'), hlimit);
|
new_wp = window_add_pane(w, wp, before, args_has(args, 'f'), hlimit);
|
||||||
layout_make_leaf(lc, new_wp);
|
layout_make_leaf(lc, new_wp);
|
||||||
|
|
||||||
path = NULL;
|
path = NULL;
|
||||||
@@ -174,7 +170,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cmd_find_from_winlink_pane(&fs, wl, new_wp, 0);
|
cmd_find_from_winlink_pane(&fs, wl, new_wp, 0);
|
||||||
hooks_insert(s->hooks, item, &fs, "after-split-window");
|
hooks_insert(s->hooks, item, &fs, "after-split-window");
|
||||||
|
|
||||||
free(to_free);
|
free(cwd);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@@ -185,6 +181,6 @@ error:
|
|||||||
cmdq_error(item, "create pane failed: %s", cause);
|
cmdq_error(item, "create pane failed: %s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
|
|
||||||
free(to_free);
|
free(cwd);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
13
cmd.c
13
cmd.c
@@ -200,6 +200,15 @@ const struct cmd_entry *cmd_table[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_log_argv(int argc, char **argv, const char *prefix)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
|
log_debug("%s: argv[%d]=%s", prefix, i, argv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
@@ -208,6 +217,7 @@ cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
|||||||
|
|
||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
cmd_log_argv(argc, argv, __func__);
|
||||||
|
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
@@ -240,9 +250,11 @@ cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
|
|||||||
|
|
||||||
arglen = strlen(buf) + 1;
|
arglen = strlen(buf) + 1;
|
||||||
(*argv)[i] = xstrdup(buf);
|
(*argv)[i] = xstrdup(buf);
|
||||||
|
|
||||||
buf += arglen;
|
buf += arglen;
|
||||||
len -= arglen;
|
len -= arglen;
|
||||||
}
|
}
|
||||||
|
cmd_log_argv(argc, *argv, __func__);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -401,6 +413,7 @@ retry:
|
|||||||
xasprintf(cause, "unknown command: %s", name);
|
xasprintf(cause, "unknown command: %s", name);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
cmd_log_argv(argc, argv, entry->name);
|
||||||
|
|
||||||
args = args_parse(entry->args.template, argc, argv);
|
args = args_parse(entry->args.template, argc, argv);
|
||||||
if (args == NULL)
|
if (args == NULL)
|
||||||
|
|||||||
4
compat.h
4
compat.h
@@ -101,17 +101,17 @@ void warnx(const char *, ...);
|
|||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_FORKPTY
|
|
||||||
#ifdef HAVE_LIBUTIL_H
|
#ifdef HAVE_LIBUTIL_H
|
||||||
#include <libutil.h>
|
#include <libutil.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_PTY_H
|
#ifdef HAVE_PTY_H
|
||||||
#include <pty.h>
|
#include <pty.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_UTIL_H
|
#ifdef HAVE_UTIL_H
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_VIS
|
#ifdef HAVE_VIS
|
||||||
#include <vis.h>
|
#include <vis.h>
|
||||||
|
|||||||
@@ -30,19 +30,12 @@ getdtablecount(void)
|
|||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
glob_t g;
|
glob_t g;
|
||||||
int n;
|
int n = 0;
|
||||||
|
|
||||||
if (snprintf(path, sizeof path, "/proc/%ld/fd/*", (long)getpid()) < 0)
|
if (snprintf(path, sizeof path, "/proc/%ld/fd/*", (long)getpid()) < 0)
|
||||||
fatal("snprintf overflow");
|
fatal("snprintf overflow");
|
||||||
switch (glob(path, 0, NULL, &g)) {
|
if (glob(path, 0, NULL, &g) == 0)
|
||||||
case GLOB_NOMATCH:
|
n = g.gl_pathc;
|
||||||
return (0);
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fatal("glob(\"%s\") failed", path);
|
|
||||||
}
|
|
||||||
n = g.gl_pathc;
|
|
||||||
globfree(&g);
|
globfree(&g);
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: imsg-buffer.c,v 1.10 2017/04/11 09:57:19 reyk Exp $ */
|
/* $OpenBSD: imsg-buffer.c,v 1.11 2017/12/14 09:27:44 kettenis Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||||
@@ -29,9 +29,9 @@
|
|||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "imsg.h"
|
#include "imsg.h"
|
||||||
|
|
||||||
int ibuf_realloc(struct ibuf *, size_t);
|
static int ibuf_realloc(struct ibuf *, size_t);
|
||||||
void ibuf_enqueue(struct msgbuf *, struct ibuf *);
|
static void ibuf_enqueue(struct msgbuf *, struct ibuf *);
|
||||||
void ibuf_dequeue(struct msgbuf *, struct ibuf *);
|
static void ibuf_dequeue(struct msgbuf *, struct ibuf *);
|
||||||
|
|
||||||
struct ibuf *
|
struct ibuf *
|
||||||
ibuf_open(size_t len)
|
ibuf_open(size_t len)
|
||||||
@@ -67,7 +67,7 @@ ibuf_dynamic(size_t len, size_t max)
|
|||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
ibuf_realloc(struct ibuf *buf, size_t len)
|
ibuf_realloc(struct ibuf *buf, size_t len)
|
||||||
{
|
{
|
||||||
u_char *b;
|
u_char *b;
|
||||||
@@ -289,14 +289,14 @@ again:
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf)
|
ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf)
|
||||||
{
|
{
|
||||||
TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry);
|
TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry);
|
||||||
msgbuf->queued++;
|
msgbuf->queued++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf)
|
ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf)
|
||||||
{
|
{
|
||||||
TAILQ_REMOVE(&msgbuf->bufs, buf, entry);
|
TAILQ_REMOVE(&msgbuf->bufs, buf, entry);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: imsg.c,v 1.15 2017/04/11 09:57:19 reyk Exp $ */
|
/* $OpenBSD: imsg.c,v 1.16 2017/12/14 09:27:44 kettenis Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
int imsg_fd_overhead = 0;
|
int imsg_fd_overhead = 0;
|
||||||
|
|
||||||
int imsg_get_fd(struct imsgbuf *);
|
static int imsg_get_fd(struct imsgbuf *);
|
||||||
|
|
||||||
void
|
void
|
||||||
imsg_init(struct imsgbuf *ibuf, int fd)
|
imsg_init(struct imsgbuf *ibuf, int fd)
|
||||||
@@ -266,7 +266,7 @@ imsg_free(struct imsg *imsg)
|
|||||||
freezero(imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE);
|
freezero(imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
imsg_get_fd(struct imsgbuf *ibuf)
|
imsg_get_fd(struct imsgbuf *ibuf)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|||||||
17
configure.ac
17
configure.ac
@@ -1,6 +1,6 @@
|
|||||||
# configure.ac
|
# configure.ac
|
||||||
|
|
||||||
AC_INIT(tmux, 2.6)
|
AC_INIT(tmux, 2.8)
|
||||||
AC_PREREQ([2.60])
|
AC_PREREQ([2.60])
|
||||||
|
|
||||||
AC_CONFIG_AUX_DIR(etc)
|
AC_CONFIG_AUX_DIR(etc)
|
||||||
@@ -285,6 +285,7 @@ if test "x$found_b64_ntop" = xno; then
|
|||||||
AC_MSG_RESULT(no)
|
AC_MSG_RESULT(no)
|
||||||
|
|
||||||
AC_MSG_CHECKING(for b64_ntop with -lresolv)
|
AC_MSG_CHECKING(for b64_ntop with -lresolv)
|
||||||
|
OLD_LIBS="$LIBS"
|
||||||
LIBS="$LIBS -lresolv"
|
LIBS="$LIBS -lresolv"
|
||||||
AC_TRY_LINK(
|
AC_TRY_LINK(
|
||||||
[
|
[
|
||||||
@@ -297,6 +298,7 @@ if test "x$found_b64_ntop" = xno; then
|
|||||||
found_b64_ntop=no
|
found_b64_ntop=no
|
||||||
)
|
)
|
||||||
if test "x$found_b64_ntop" = xno; then
|
if test "x$found_b64_ntop" = xno; then
|
||||||
|
LIBS="$OLD_LIBS"
|
||||||
AC_MSG_RESULT(no)
|
AC_MSG_RESULT(no)
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -608,13 +610,22 @@ case "$host_os" in
|
|||||||
*solaris*)
|
*solaris*)
|
||||||
AC_MSG_RESULT(sunos)
|
AC_MSG_RESULT(sunos)
|
||||||
PLATFORM=sunos
|
PLATFORM=sunos
|
||||||
MANFORMAT=man
|
case `/usr/bin/nroff --version 2>&1` in
|
||||||
|
*GNU*)
|
||||||
|
# Solaris 11.4 and later use GNU groff.
|
||||||
|
MANFORMAT=mdoc
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# Solaris 2.0 to 11.3 use AT&T nroff.
|
||||||
|
MANFORMAT=man
|
||||||
|
;;
|
||||||
|
esac
|
||||||
;;
|
;;
|
||||||
*hpux*)
|
*hpux*)
|
||||||
AC_MSG_RESULT(hpux)
|
AC_MSG_RESULT(hpux)
|
||||||
PLATFORM=hpux
|
PLATFORM=hpux
|
||||||
;;
|
;;
|
||||||
*cygwin*)
|
*cygwin*|*msys*)
|
||||||
AC_MSG_RESULT(cygwin)
|
AC_MSG_RESULT(cygwin)
|
||||||
PLATFORM=cygwin
|
PLATFORM=cygwin
|
||||||
;;
|
;;
|
||||||
|
|||||||
153
format.c
153
format.c
@@ -19,6 +19,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
@@ -191,10 +192,15 @@ static void
|
|||||||
format_job_update(struct job *job)
|
format_job_update(struct job *job)
|
||||||
{
|
{
|
||||||
struct format_job *fj = job->data;
|
struct format_job *fj = job->data;
|
||||||
char *line;
|
struct evbuffer *evb = job->event->input;
|
||||||
|
char *line = NULL, *next;
|
||||||
time_t t;
|
time_t t;
|
||||||
|
|
||||||
if ((line = evbuffer_readline(job->event->input)) == NULL)
|
while ((next = evbuffer_readline(evb)) != NULL) {
|
||||||
|
free(line);
|
||||||
|
line = next;
|
||||||
|
}
|
||||||
|
if (line == NULL)
|
||||||
return;
|
return;
|
||||||
fj->updated = 1;
|
fj->updated = 1;
|
||||||
|
|
||||||
@@ -290,7 +296,7 @@ format_job_get(struct format_tree *ft, const char *cmd)
|
|||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
if (fj->job == NULL && (force || fj->last != t)) {
|
if (fj->job == NULL && (force || fj->last != t)) {
|
||||||
fj->job = job_run(expanded, NULL, NULL, format_job_update,
|
fj->job = job_run(expanded, NULL, NULL, format_job_update,
|
||||||
format_job_complete, NULL, fj);
|
format_job_complete, NULL, fj, JOB_NOWAIT);
|
||||||
if (fj->job == NULL) {
|
if (fj->job == NULL) {
|
||||||
free(fj->out);
|
free(fj->out);
|
||||||
xasprintf(&fj->out, "<'%s' didn't start>", fj->cmd);
|
xasprintf(&fj->out, "<'%s' didn't start>", fj->cmd);
|
||||||
@@ -557,11 +563,11 @@ format_cb_history_bytes(struct format_tree *ft, struct format_entry *fe)
|
|||||||
|
|
||||||
size = 0;
|
size = 0;
|
||||||
for (i = 0; i < gd->hsize; i++) {
|
for (i = 0; i < gd->hsize; i++) {
|
||||||
gl = &gd->linedata[i];
|
gl = grid_get_line(gd, i);
|
||||||
size += gl->cellsize * sizeof *gl->celldata;
|
size += gl->cellsize * sizeof *gl->celldata;
|
||||||
size += gl->extdsize * sizeof *gl->extddata;
|
size += gl->extdsize * sizeof *gl->extddata;
|
||||||
}
|
}
|
||||||
size += gd->hsize * sizeof *gd->linedata;
|
size += gd->hsize * sizeof *gl;
|
||||||
|
|
||||||
xasprintf(&fe->value, "%llu", size);
|
xasprintf(&fe->value, "%llu", size);
|
||||||
}
|
}
|
||||||
@@ -587,8 +593,35 @@ format_cb_pane_tabs(struct format_tree *ft, struct format_entry *fe)
|
|||||||
evbuffer_add(buffer, ",", 1);
|
evbuffer_add(buffer, ",", 1);
|
||||||
evbuffer_add_printf(buffer, "%u", i);
|
evbuffer_add_printf(buffer, "%u", i);
|
||||||
}
|
}
|
||||||
size = EVBUFFER_LENGTH(buffer);
|
if ((size = EVBUFFER_LENGTH(buffer)) != 0)
|
||||||
xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer));
|
xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer));
|
||||||
|
evbuffer_free(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Callback for session_group_list. */
|
||||||
|
static void
|
||||||
|
format_cb_session_group_list(struct format_tree *ft, struct format_entry *fe)
|
||||||
|
{
|
||||||
|
struct session *s = ft->s;
|
||||||
|
struct session_group *sg;
|
||||||
|
struct session *loop;
|
||||||
|
struct evbuffer *buffer;
|
||||||
|
int size;
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return;
|
||||||
|
sg = session_group_contains(s);
|
||||||
|
if (sg == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
buffer = evbuffer_new();
|
||||||
|
TAILQ_FOREACH(loop, &sg->sessions, gentry) {
|
||||||
|
if (EVBUFFER_LENGTH(buffer) > 0)
|
||||||
|
evbuffer_add(buffer, ",", 1);
|
||||||
|
evbuffer_add_printf(buffer, "%s", loop->name);
|
||||||
|
}
|
||||||
|
if ((size = EVBUFFER_LENGTH(buffer)) != 0)
|
||||||
|
xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer));
|
||||||
evbuffer_free(buffer);
|
evbuffer_free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -781,8 +814,11 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
|
|||||||
found = s;
|
found = s;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
if (fe->value == NULL && fe->cb != NULL)
|
if (fe->value == NULL && fe->cb != NULL) {
|
||||||
fe->cb(ft, fe);
|
fe->cb(ft, fe);
|
||||||
|
if (fe->value == NULL)
|
||||||
|
fe->value = xstrdup("");
|
||||||
|
}
|
||||||
found = fe->value;
|
found = fe->value;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
@@ -818,18 +854,22 @@ found:
|
|||||||
return (copy);
|
return (copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip until comma. */
|
/* Skip until end. */
|
||||||
static char *
|
static const char *
|
||||||
format_skip(char *s)
|
format_skip(const char *s, char end)
|
||||||
{
|
{
|
||||||
int brackets = 0;
|
int brackets = 0;
|
||||||
|
|
||||||
for (; *s != '\0'; s++) {
|
for (; *s != '\0'; s++) {
|
||||||
if (*s == '{')
|
if (*s == '#' && s[1] == '{')
|
||||||
brackets++;
|
brackets++;
|
||||||
|
if (*s == '#' && strchr(",#{}", s[1]) != NULL) {
|
||||||
|
s++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (*s == '}')
|
if (*s == '}')
|
||||||
brackets--;
|
brackets--;
|
||||||
if (*s == ',' && brackets == 0)
|
if (*s == end && brackets == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*s == '\0')
|
if (*s == '\0')
|
||||||
@@ -843,7 +883,7 @@ format_choose(char *s, char **left, char **right)
|
|||||||
{
|
{
|
||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
cp = format_skip(s);
|
cp = (char *)format_skip(s, ',');
|
||||||
if (cp == NULL)
|
if (cp == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
@@ -868,11 +908,12 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
|||||||
char **buf, size_t *len, size_t *off)
|
char **buf, size_t *len, size_t *off)
|
||||||
{
|
{
|
||||||
struct window_pane *wp = ft->wp;
|
struct window_pane *wp = ft->wp;
|
||||||
char *copy, *copy0, *endptr, *ptr, *found, *new;
|
char *copy, *copy0, *endptr, *ptr, *found, *new, sep;
|
||||||
char *value, *from = NULL, *to = NULL, *left, *right;
|
char *value, *from = NULL, *to = NULL, *left, *right;
|
||||||
size_t valuelen, newlen, fromlen, tolen, used;
|
size_t valuelen, newlen, fromlen, tolen, used;
|
||||||
long limit = 0;
|
long limit = 0;
|
||||||
int modifiers = 0, compare = 0, search = 0;
|
int modifiers = 0, compare = 0, search = 0;
|
||||||
|
int literal = 0;
|
||||||
|
|
||||||
/* Make a copy of the key. */
|
/* Make a copy of the key. */
|
||||||
copy0 = copy = xmalloc(keylen + 1);
|
copy0 = copy = xmalloc(keylen + 1);
|
||||||
@@ -881,6 +922,12 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
|||||||
|
|
||||||
/* Is there a length limit or whatnot? */
|
/* Is there a length limit or whatnot? */
|
||||||
switch (copy[0]) {
|
switch (copy[0]) {
|
||||||
|
case 'l':
|
||||||
|
if (copy[1] != ':')
|
||||||
|
break;
|
||||||
|
literal = 1;
|
||||||
|
copy += 2;
|
||||||
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
if (copy[1] != ':')
|
if (copy[1] != ':')
|
||||||
break;
|
break;
|
||||||
@@ -945,20 +992,21 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
|||||||
copy += 2;
|
copy += 2;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (copy[1] != '/')
|
sep = copy[1];
|
||||||
|
if (sep == ':' || !ispunct((u_char)sep))
|
||||||
break;
|
break;
|
||||||
from = copy + 2;
|
from = copy + 2;
|
||||||
for (copy = from; *copy != '\0' && *copy != '/'; copy++)
|
for (copy = from; *copy != '\0' && *copy != sep; copy++)
|
||||||
/* nothing */;
|
/* nothing */;
|
||||||
if (copy[0] != '/' || copy == from) {
|
if (copy[0] != sep || copy == from) {
|
||||||
copy = copy0;
|
copy = copy0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
copy[0] = '\0';
|
copy[0] = '\0';
|
||||||
to = copy + 1;
|
to = copy + 1;
|
||||||
for (copy = to; *copy != '\0' && *copy != '/'; copy++)
|
for (copy = to; *copy != '\0' && *copy != sep; copy++)
|
||||||
/* nothing */;
|
/* nothing */;
|
||||||
if (copy[0] != '/' || copy[1] != ':') {
|
if (copy[0] != sep || copy[1] != ':') {
|
||||||
copy = copy0;
|
copy = copy0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -969,6 +1017,12 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Is this a literal string? */
|
||||||
|
if (literal) {
|
||||||
|
value = xstrdup(copy);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
/* Is this a comparison or a conditional? */
|
/* Is this a comparison or a conditional? */
|
||||||
if (search) {
|
if (search) {
|
||||||
/* Search in pane. */
|
/* Search in pane. */
|
||||||
@@ -1000,14 +1054,24 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
|||||||
free(left);
|
free(left);
|
||||||
} else if (*copy == '?') {
|
} else if (*copy == '?') {
|
||||||
/* Conditional: check first and choose second or third. */
|
/* Conditional: check first and choose second or third. */
|
||||||
ptr = format_skip(copy);
|
ptr = (char *)format_skip(copy, ',');
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
goto fail;
|
goto fail;
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
|
||||||
found = format_find(ft, copy + 1, modifiers);
|
found = format_find(ft, copy + 1, modifiers);
|
||||||
if (found == NULL)
|
if (found == NULL) {
|
||||||
|
/*
|
||||||
|
* If the conditional not found, try to expand it. If
|
||||||
|
* the expansion doesn't have any effect, then assume
|
||||||
|
* false.
|
||||||
|
*/
|
||||||
found = format_expand(ft, copy + 1);
|
found = format_expand(ft, copy + 1);
|
||||||
|
if (strcmp(found, copy + 1) == 0) {
|
||||||
|
free(found);
|
||||||
|
found = xstrdup("");
|
||||||
|
}
|
||||||
|
}
|
||||||
if (format_choose(ptr + 1, &left, &right) != 0)
|
if (format_choose(ptr + 1, &left, &right) != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
@@ -1062,6 +1126,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
|||||||
value = new;
|
value = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
/* Expand the buffer and copy in the value. */
|
/* Expand the buffer and copy in the value. */
|
||||||
valuelen = strlen(value);
|
valuelen = strlen(value);
|
||||||
while (*len - *off < valuelen + 1) {
|
while (*len - *off < valuelen + 1) {
|
||||||
@@ -1102,7 +1167,7 @@ format_expand_time(struct format_tree *ft, const char *fmt, time_t t)
|
|||||||
char *
|
char *
|
||||||
format_expand(struct format_tree *ft, const char *fmt)
|
format_expand(struct format_tree *ft, const char *fmt)
|
||||||
{
|
{
|
||||||
char *buf, *out;
|
char *buf, *out, *name;
|
||||||
const char *ptr, *s, *saved = fmt;
|
const char *ptr, *s, *saved = fmt;
|
||||||
size_t off, len, n, outlen;
|
size_t off, len, n, outlen;
|
||||||
int ch, brackets;
|
int ch, brackets;
|
||||||
@@ -1141,8 +1206,11 @@ format_expand(struct format_tree *ft, const char *fmt)
|
|||||||
|
|
||||||
if (ft->flags & FORMAT_NOJOBS)
|
if (ft->flags & FORMAT_NOJOBS)
|
||||||
out = xstrdup("");
|
out = xstrdup("");
|
||||||
else
|
else {
|
||||||
out = format_job_get(ft, xstrndup(fmt, n));
|
name = xstrndup(fmt, n);
|
||||||
|
out = format_job_get(ft, name);
|
||||||
|
free(name);
|
||||||
|
}
|
||||||
outlen = strlen(out);
|
outlen = strlen(out);
|
||||||
|
|
||||||
while (len - off < outlen + 1) {
|
while (len - off < outlen + 1) {
|
||||||
@@ -1157,14 +1225,8 @@ format_expand(struct format_tree *ft, const char *fmt)
|
|||||||
fmt += n + 1;
|
fmt += n + 1;
|
||||||
continue;
|
continue;
|
||||||
case '{':
|
case '{':
|
||||||
brackets = 1;
|
ptr = format_skip(fmt - 2, '}');
|
||||||
for (ptr = fmt; *ptr != '\0'; ptr++) {
|
if (ptr == NULL)
|
||||||
if (*ptr == '{')
|
|
||||||
brackets++;
|
|
||||||
if (*ptr == '}' && --brackets == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (*ptr != '}' || brackets != 0)
|
|
||||||
break;
|
break;
|
||||||
n = ptr - fmt;
|
n = ptr - fmt;
|
||||||
|
|
||||||
@@ -1172,12 +1234,14 @@ format_expand(struct format_tree *ft, const char *fmt)
|
|||||||
break;
|
break;
|
||||||
fmt += n + 1;
|
fmt += n + 1;
|
||||||
continue;
|
continue;
|
||||||
|
case '}':
|
||||||
case '#':
|
case '#':
|
||||||
|
case ',':
|
||||||
while (len - off < 2) {
|
while (len - off < 2) {
|
||||||
buf = xreallocarray(buf, 2, len);
|
buf = xreallocarray(buf, 2, len);
|
||||||
len *= 2;
|
len *= 2;
|
||||||
}
|
}
|
||||||
buf[off++] = '#';
|
buf[off++] = ch;
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
s = NULL;
|
s = NULL;
|
||||||
@@ -1232,6 +1296,9 @@ void
|
|||||||
format_defaults(struct format_tree *ft, struct client *c, struct session *s,
|
format_defaults(struct format_tree *ft, struct client *c, struct session *s,
|
||||||
struct winlink *wl, struct window_pane *wp)
|
struct winlink *wl, struct window_pane *wp)
|
||||||
{
|
{
|
||||||
|
if (c != NULL && s != NULL && c->session != s)
|
||||||
|
log_debug("%s: session does not match", __func__);
|
||||||
|
|
||||||
format_add(ft, "session_format", "%d", s != NULL);
|
format_add(ft, "session_format", "%d", s != NULL);
|
||||||
format_add(ft, "window_format", "%d", wl != NULL);
|
format_add(ft, "window_format", "%d", wl != NULL);
|
||||||
format_add(ft, "pane_format", "%d", wp != NULL);
|
format_add(ft, "pane_format", "%d", wp != NULL);
|
||||||
@@ -1269,8 +1336,13 @@ format_defaults_session(struct format_tree *ft, struct session *s)
|
|||||||
|
|
||||||
sg = session_group_contains(s);
|
sg = session_group_contains(s);
|
||||||
format_add(ft, "session_grouped", "%d", sg != NULL);
|
format_add(ft, "session_grouped", "%d", sg != NULL);
|
||||||
if (sg != NULL)
|
if (sg != NULL) {
|
||||||
format_add(ft, "session_group", "%s", sg->name);
|
format_add(ft, "session_group", "%s", sg->name);
|
||||||
|
format_add(ft, "session_group_size", "%u",
|
||||||
|
session_group_count (sg));
|
||||||
|
format_add_cb(ft, "session_group_list",
|
||||||
|
format_cb_session_group_list);
|
||||||
|
}
|
||||||
|
|
||||||
format_add_tv(ft, "session_created", &s->creation_time);
|
format_add_tv(ft, "session_created", &s->creation_time);
|
||||||
format_add_tv(ft, "session_last_attached", &s->last_attached_time);
|
format_add_tv(ft, "session_last_attached", &s->last_attached_time);
|
||||||
@@ -1392,8 +1464,8 @@ void
|
|||||||
format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
|
format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
|
||||||
{
|
{
|
||||||
struct grid *gd = wp->base.grid;
|
struct grid *gd = wp->base.grid;
|
||||||
|
int status = wp->status;
|
||||||
u_int idx;
|
u_int idx;
|
||||||
int status;
|
|
||||||
|
|
||||||
if (ft->w == NULL)
|
if (ft->w == NULL)
|
||||||
ft->w = wp->window;
|
ft->w = wp->window;
|
||||||
@@ -1415,8 +1487,7 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
|
|||||||
format_add(ft, "pane_input_off", "%d", !!(wp->flags & PANE_INPUTOFF));
|
format_add(ft, "pane_input_off", "%d", !!(wp->flags & PANE_INPUTOFF));
|
||||||
format_add(ft, "pane_pipe", "%d", wp->pipe_fd != -1);
|
format_add(ft, "pane_pipe", "%d", wp->pipe_fd != -1);
|
||||||
|
|
||||||
status = wp->status;
|
if ((wp->flags & PANE_STATUSREADY) && WIFEXITED(status))
|
||||||
if (wp->fd == -1 && WIFEXITED(status))
|
|
||||||
format_add(ft, "pane_dead_status", "%d", WEXITSTATUS(status));
|
format_add(ft, "pane_dead_status", "%d", WEXITSTATUS(status));
|
||||||
format_add(ft, "pane_dead", "%d", wp->fd == -1);
|
format_add(ft, "pane_dead", "%d", wp->fd == -1);
|
||||||
|
|
||||||
@@ -1427,8 +1498,10 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
|
|||||||
format_add(ft, "pane_bottom", "%u", wp->yoff + wp->sy - 1);
|
format_add(ft, "pane_bottom", "%u", wp->yoff + wp->sy - 1);
|
||||||
format_add(ft, "pane_at_left", "%d", wp->xoff == 0);
|
format_add(ft, "pane_at_left", "%d", wp->xoff == 0);
|
||||||
format_add(ft, "pane_at_top", "%d", wp->yoff == 0);
|
format_add(ft, "pane_at_top", "%d", wp->yoff == 0);
|
||||||
format_add(ft, "pane_at_right", "%d", wp->xoff + wp->sx == wp->window->sx);
|
format_add(ft, "pane_at_right", "%d",
|
||||||
format_add(ft, "pane_at_bottom", "%d", wp->yoff + wp->sy == wp->window->sy);
|
wp->xoff + wp->sx == wp->window->sx);
|
||||||
|
format_add(ft, "pane_at_bottom", "%d",
|
||||||
|
wp->yoff + wp->sy == wp->window->sy);
|
||||||
}
|
}
|
||||||
|
|
||||||
format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base);
|
format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ grid_view_clear_history(struct grid *gd, u_int bg)
|
|||||||
/* Find the last used line. */
|
/* Find the last used line. */
|
||||||
last = 0;
|
last = 0;
|
||||||
for (yy = 0; yy < gd->sy; yy++) {
|
for (yy = 0; yy < gd->sy; yy++) {
|
||||||
gl = &gd->linedata[grid_view_y(gd, yy)];
|
gl = grid_get_line(gd, grid_view_y(gd, yy));
|
||||||
if (gl->cellused != 0)
|
if (gl->cellused != 0)
|
||||||
last = yy + 1;
|
last = yy + 1;
|
||||||
}
|
}
|
||||||
|
|||||||
574
grid.c
574
grid.c
@@ -43,22 +43,8 @@ static const struct grid_cell_entry grid_default_entry = {
|
|||||||
0, { .data = { 0, 8, 8, ' ' } }
|
0, { .data = { 0, 8, 8, ' ' } }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void grid_expand_line(struct grid *, u_int, u_int, u_int);
|
|
||||||
static void grid_empty_line(struct grid *, u_int, u_int);
|
static void grid_empty_line(struct grid *, u_int, u_int);
|
||||||
|
|
||||||
static void grid_reflow_copy(struct grid_line *, u_int, struct grid_line *,
|
|
||||||
u_int, u_int);
|
|
||||||
static void grid_reflow_join(struct grid *, u_int *, struct grid_line *,
|
|
||||||
u_int);
|
|
||||||
static void grid_reflow_split(struct grid *, u_int *, struct grid_line *,
|
|
||||||
u_int, u_int);
|
|
||||||
static void grid_reflow_move(struct grid *, u_int *, struct grid_line *);
|
|
||||||
|
|
||||||
static size_t grid_string_cells_fg(const struct grid_cell *, int *);
|
|
||||||
static size_t grid_string_cells_bg(const struct grid_cell *, int *);
|
|
||||||
static void grid_string_cells_code(const struct grid_cell *,
|
|
||||||
const struct grid_cell *, char *, size_t, int);
|
|
||||||
|
|
||||||
/* Store cell in entry. */
|
/* Store cell in entry. */
|
||||||
static void
|
static void
|
||||||
grid_store_cell(struct grid_cell_entry *gce, const struct grid_cell *gc,
|
grid_store_cell(struct grid_cell_entry *gce, const struct grid_cell *gc,
|
||||||
@@ -159,6 +145,20 @@ grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
|
|||||||
return (gcp);
|
return (gcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get line data. */
|
||||||
|
struct grid_line *
|
||||||
|
grid_get_line(struct grid *gd, u_int line)
|
||||||
|
{
|
||||||
|
return (&gd->linedata[line]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adjust number of lines. */
|
||||||
|
void
|
||||||
|
grid_adjust_lines(struct grid *gd, u_int lines)
|
||||||
|
{
|
||||||
|
gd->linedata = xreallocarray(gd->linedata, lines, sizeof *gd->linedata);
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy default into a cell. */
|
/* Copy default into a cell. */
|
||||||
static void
|
static void
|
||||||
grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
|
grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
|
||||||
@@ -180,10 +180,10 @@ grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
|
|||||||
|
|
||||||
/* Check grid y position. */
|
/* Check grid y position. */
|
||||||
static int
|
static int
|
||||||
grid_check_y(struct grid *gd, u_int py)
|
grid_check_y(struct grid *gd, const char* from, u_int py)
|
||||||
{
|
{
|
||||||
if ((py) >= (gd)->hsize + (gd)->sy) {
|
if (py >= gd->hsize + gd->sy) {
|
||||||
log_debug("y out of range: %u", py);
|
log_debug("%s: y out of range: %u", from, py);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@@ -240,7 +240,10 @@ grid_create(u_int sx, u_int sy, u_int hlimit)
|
|||||||
gd->hsize = 0;
|
gd->hsize = 0;
|
||||||
gd->hlimit = hlimit;
|
gd->hlimit = hlimit;
|
||||||
|
|
||||||
gd->linedata = xcalloc(gd->sy, sizeof *gd->linedata);
|
if (gd->sy != 0)
|
||||||
|
gd->linedata = xcalloc(gd->sy, sizeof *gd->linedata);
|
||||||
|
else
|
||||||
|
gd->linedata = NULL;
|
||||||
|
|
||||||
return (gd);
|
return (gd);
|
||||||
}
|
}
|
||||||
@@ -283,6 +286,15 @@ grid_compare(struct grid *ga, struct grid *gb)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Trim lines from the history. */
|
||||||
|
static void
|
||||||
|
grid_trim_history(struct grid *gd, u_int ny)
|
||||||
|
{
|
||||||
|
grid_free_lines(gd, 0, ny);
|
||||||
|
memmove(&gd->linedata[0], &gd->linedata[ny],
|
||||||
|
(gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Collect lines from the history if at the limit. Free the top (oldest) 10%
|
* Collect lines from the history if at the limit. Free the top (oldest) 10%
|
||||||
* and shift up.
|
* and shift up.
|
||||||
@@ -305,9 +317,7 @@ grid_collect_history(struct grid *gd)
|
|||||||
* Free the lines from 0 to ny then move the remaining lines over
|
* Free the lines from 0 to ny then move the remaining lines over
|
||||||
* them.
|
* them.
|
||||||
*/
|
*/
|
||||||
grid_free_lines(gd, 0, ny);
|
grid_trim_history(gd, ny);
|
||||||
memmove(&gd->linedata[0], &gd->linedata[ny],
|
|
||||||
(gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
|
|
||||||
|
|
||||||
gd->hsize -= ny;
|
gd->hsize -= ny;
|
||||||
if (gd->hscrolled > gd->hsize)
|
if (gd->hscrolled > gd->hsize)
|
||||||
@@ -337,9 +347,7 @@ grid_scroll_history(struct grid *gd, u_int bg)
|
|||||||
void
|
void
|
||||||
grid_clear_history(struct grid *gd)
|
grid_clear_history(struct grid *gd)
|
||||||
{
|
{
|
||||||
grid_free_lines(gd, 0, gd->hsize);
|
grid_trim_history(gd, gd->hsize);
|
||||||
memmove(&gd->linedata[0], &gd->linedata[gd->hsize],
|
|
||||||
gd->sy * (sizeof *gd->linedata));
|
|
||||||
|
|
||||||
gd->hscrolled = 0;
|
gd->hscrolled = 0;
|
||||||
gd->hsize = 0;
|
gd->hsize = 0;
|
||||||
@@ -418,25 +426,16 @@ grid_empty_line(struct grid *gd, u_int py, u_int bg)
|
|||||||
const struct grid_line *
|
const struct grid_line *
|
||||||
grid_peek_line(struct grid *gd, u_int py)
|
grid_peek_line(struct grid *gd, u_int py)
|
||||||
{
|
{
|
||||||
if (grid_check_y(gd, py) != 0)
|
if (grid_check_y(gd, __func__, py) != 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
return (&gd->linedata[py]);
|
return (&gd->linedata[py]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get cell for reading. */
|
/* Get cell from line. */
|
||||||
void
|
static void
|
||||||
grid_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)
|
grid_get_cell1(struct grid_line *gl, u_int px, struct grid_cell *gc)
|
||||||
{
|
{
|
||||||
struct grid_line *gl;
|
struct grid_cell_entry *gce = &gl->celldata[px];
|
||||||
struct grid_cell_entry *gce;
|
|
||||||
|
|
||||||
if (grid_check_y(gd, py) != 0 || px >= gd->linedata[py].cellsize) {
|
|
||||||
memcpy(gc, &grid_default_cell, sizeof *gc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gl = &gd->linedata[py];
|
|
||||||
gce = &gl->celldata[px];
|
|
||||||
|
|
||||||
if (gce->flags & GRID_FLAG_EXTENDED) {
|
if (gce->flags & GRID_FLAG_EXTENDED) {
|
||||||
if (gce->offset >= gl->extdsize)
|
if (gce->offset >= gl->extdsize)
|
||||||
@@ -457,6 +456,18 @@ grid_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)
|
|||||||
utf8_set(&gc->data, gce->data.data);
|
utf8_set(&gc->data, gce->data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get cell for reading. */
|
||||||
|
void
|
||||||
|
grid_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)
|
||||||
|
{
|
||||||
|
if (grid_check_y(gd, __func__, py) != 0 ||
|
||||||
|
px >= gd->linedata[py].cellsize) {
|
||||||
|
memcpy(gc, &grid_default_cell, sizeof *gc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return (grid_get_cell1(&gd->linedata[py], px, gc));
|
||||||
|
}
|
||||||
|
|
||||||
/* Set cell at relative position. */
|
/* Set cell at relative position. */
|
||||||
void
|
void
|
||||||
grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
|
grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
|
||||||
@@ -464,7 +475,7 @@ grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
|
|||||||
struct grid_line *gl;
|
struct grid_line *gl;
|
||||||
struct grid_cell_entry *gce;
|
struct grid_cell_entry *gce;
|
||||||
|
|
||||||
if (grid_check_y(gd, py) != 0)
|
if (grid_check_y(gd, __func__, py) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
grid_expand_line(gd, py, px + 1, 8);
|
grid_expand_line(gd, py, px + 1, 8);
|
||||||
@@ -490,7 +501,7 @@ grid_set_cells(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc,
|
|||||||
struct grid_cell *gcp;
|
struct grid_cell *gcp;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
if (grid_check_y(gd, py) != 0)
|
if (grid_check_y(gd, __func__, py) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
grid_expand_line(gd, py, px + slen, 8);
|
grid_expand_line(gd, py, px + slen, 8);
|
||||||
@@ -523,9 +534,9 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grid_check_y(gd, py) != 0)
|
if (grid_check_y(gd, __func__, py) != 0)
|
||||||
return;
|
return;
|
||||||
if (grid_check_y(gd, py + ny - 1) != 0)
|
if (grid_check_y(gd, __func__, py + ny - 1) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (yy = py; yy < py + ny; yy++) {
|
for (yy = py; yy < py + ny; yy++) {
|
||||||
@@ -552,9 +563,9 @@ grid_clear_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
|
|||||||
if (ny == 0)
|
if (ny == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (grid_check_y(gd, py) != 0)
|
if (grid_check_y(gd, __func__, py) != 0)
|
||||||
return;
|
return;
|
||||||
if (grid_check_y(gd, py + ny - 1) != 0)
|
if (grid_check_y(gd, __func__, py + ny - 1) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (yy = py; yy < py + ny; yy++) {
|
for (yy = py; yy < py + ny; yy++) {
|
||||||
@@ -572,13 +583,13 @@ grid_move_lines(struct grid *gd, u_int dy, u_int py, u_int ny, u_int bg)
|
|||||||
if (ny == 0 || py == dy)
|
if (ny == 0 || py == dy)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (grid_check_y(gd, py) != 0)
|
if (grid_check_y(gd, __func__, py) != 0)
|
||||||
return;
|
return;
|
||||||
if (grid_check_y(gd, py + ny - 1) != 0)
|
if (grid_check_y(gd, __func__, py + ny - 1) != 0)
|
||||||
return;
|
return;
|
||||||
if (grid_check_y(gd, dy) != 0)
|
if (grid_check_y(gd, __func__, dy) != 0)
|
||||||
return;
|
return;
|
||||||
if (grid_check_y(gd, dy + ny - 1) != 0)
|
if (grid_check_y(gd, __func__, dy + ny - 1) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Free any lines which are being replaced. */
|
/* Free any lines which are being replaced. */
|
||||||
@@ -612,7 +623,7 @@ grid_move_cells(struct grid *gd, u_int dx, u_int px, u_int py, u_int nx,
|
|||||||
if (nx == 0 || px == dx)
|
if (nx == 0 || px == dx)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (grid_check_y(gd, py) != 0)
|
if (grid_check_y(gd, __func__, py) != 0)
|
||||||
return;
|
return;
|
||||||
gl = &gd->linedata[py];
|
gl = &gd->linedata[py];
|
||||||
|
|
||||||
@@ -953,164 +964,327 @@ grid_duplicate_lines(struct grid *dst, u_int dy, struct grid *src, u_int sy,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy a section of a line. */
|
/* Mark line as dead. */
|
||||||
static void
|
static void
|
||||||
grid_reflow_copy(struct grid_line *dst_gl, u_int to, struct grid_line *src_gl,
|
grid_reflow_dead(struct grid_line *gl)
|
||||||
u_int from, u_int to_copy)
|
|
||||||
{
|
{
|
||||||
struct grid_cell_entry *gce;
|
memset(gl, 0, sizeof *gl);
|
||||||
u_int i, was;
|
gl->flags = GRID_LINE_DEAD;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(&dst_gl->celldata[to], &src_gl->celldata[from],
|
/* Add lines, return the first new one. */
|
||||||
to_copy * sizeof *dst_gl->celldata);
|
static struct grid_line *
|
||||||
|
grid_reflow_add(struct grid *gd, u_int n)
|
||||||
|
{
|
||||||
|
struct grid_line *gl;
|
||||||
|
u_int sy = gd->sy + n;
|
||||||
|
|
||||||
for (i = to; i < to + to_copy; i++) {
|
gd->linedata = xreallocarray(gd->linedata, sy, sizeof *gd->linedata);
|
||||||
gce = &dst_gl->celldata[i];
|
gl = &gd->linedata[gd->sy];
|
||||||
if (~gce->flags & GRID_FLAG_EXTENDED)
|
memset(gl, 0, n * (sizeof *gl));
|
||||||
|
gd->sy = sy;
|
||||||
|
return (gl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move a line across. */
|
||||||
|
static struct grid_line *
|
||||||
|
grid_reflow_move(struct grid *gd, struct grid_line *from)
|
||||||
|
{
|
||||||
|
struct grid_line *to;
|
||||||
|
|
||||||
|
to = grid_reflow_add(gd, 1);
|
||||||
|
memcpy(to, from, sizeof *to);
|
||||||
|
grid_reflow_dead(from);
|
||||||
|
return (to);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Join line below onto this one. */
|
||||||
|
static void
|
||||||
|
grid_reflow_join(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||||
|
u_int width, u_int *cy, int already)
|
||||||
|
{
|
||||||
|
struct grid_line *gl, *from = NULL;
|
||||||
|
struct grid_cell gc;
|
||||||
|
u_int lines, left, i, to, line, want = 0;
|
||||||
|
u_int at;
|
||||||
|
int wrapped = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add a new target line.
|
||||||
|
*/
|
||||||
|
if (!already) {
|
||||||
|
to = target->sy;
|
||||||
|
gl = grid_reflow_move(target, &gd->linedata[yy]);
|
||||||
|
} else {
|
||||||
|
to = target->sy - 1;
|
||||||
|
gl = &target->linedata[to];
|
||||||
|
}
|
||||||
|
at = gl->cellused;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loop until no more to consume or the target line is full.
|
||||||
|
*/
|
||||||
|
lines = 0;
|
||||||
|
for (;;) {
|
||||||
|
/*
|
||||||
|
* If this is now the last line, there is nothing more to be
|
||||||
|
* done.
|
||||||
|
*/
|
||||||
|
if (yy + 1 + lines == gd->hsize + gd->sy)
|
||||||
|
break;
|
||||||
|
line = yy + 1 + lines;
|
||||||
|
|
||||||
|
/* If the next line is empty, skip it. */
|
||||||
|
if (~gd->linedata[line].flags & GRID_LINE_WRAPPED)
|
||||||
|
wrapped = 0;
|
||||||
|
if (gd->linedata[line].cellused == 0) {
|
||||||
|
if (!wrapped)
|
||||||
|
break;
|
||||||
|
lines++;
|
||||||
continue;
|
continue;
|
||||||
was = gce->offset;
|
|
||||||
|
|
||||||
dst_gl->extddata = xreallocarray(dst_gl->extddata,
|
|
||||||
dst_gl->extdsize + 1, sizeof *dst_gl->extddata);
|
|
||||||
gce->offset = dst_gl->extdsize++;
|
|
||||||
memcpy(&dst_gl->extddata[gce->offset], &src_gl->extddata[was],
|
|
||||||
sizeof *dst_gl->extddata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Join line data. */
|
|
||||||
static void
|
|
||||||
grid_reflow_join(struct grid *dst, u_int *py, struct grid_line *src_gl,
|
|
||||||
u_int new_x)
|
|
||||||
{
|
|
||||||
struct grid_line *dst_gl = &dst->linedata[(*py) - 1];
|
|
||||||
u_int left, to_copy, ox, nx;
|
|
||||||
|
|
||||||
/* How much is left on the old line? */
|
|
||||||
left = new_x - dst_gl->cellused;
|
|
||||||
|
|
||||||
/* Work out how much to append. */
|
|
||||||
to_copy = src_gl->cellused;
|
|
||||||
if (to_copy > left)
|
|
||||||
to_copy = left;
|
|
||||||
ox = dst_gl->cellused;
|
|
||||||
nx = ox + to_copy;
|
|
||||||
|
|
||||||
/* Resize the destination line. */
|
|
||||||
dst_gl->celldata = xreallocarray(dst_gl->celldata, nx,
|
|
||||||
sizeof *dst_gl->celldata);
|
|
||||||
dst_gl->cellsize = dst_gl->cellused = nx;
|
|
||||||
|
|
||||||
/* Append as much as possible. */
|
|
||||||
grid_reflow_copy(dst_gl, ox, src_gl, 0, to_copy);
|
|
||||||
|
|
||||||
/* If there is any left in the source, split it. */
|
|
||||||
if (src_gl->cellused > to_copy) {
|
|
||||||
dst_gl->flags |= GRID_LINE_WRAPPED;
|
|
||||||
|
|
||||||
src_gl->cellused -= to_copy;
|
|
||||||
grid_reflow_split(dst, py, src_gl, new_x, to_copy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Split line data. */
|
|
||||||
static void
|
|
||||||
grid_reflow_split(struct grid *dst, u_int *py, struct grid_line *src_gl,
|
|
||||||
u_int new_x, u_int offset)
|
|
||||||
{
|
|
||||||
struct grid_line *dst_gl = NULL;
|
|
||||||
u_int to_copy;
|
|
||||||
|
|
||||||
/* Loop and copy sections of the source line. */
|
|
||||||
while (src_gl->cellused > 0) {
|
|
||||||
/* Create new line. */
|
|
||||||
if (*py >= dst->hsize + dst->sy)
|
|
||||||
grid_scroll_history(dst, 8);
|
|
||||||
dst_gl = &dst->linedata[*py];
|
|
||||||
(*py)++;
|
|
||||||
|
|
||||||
/* How much should we copy? */
|
|
||||||
to_copy = new_x;
|
|
||||||
if (to_copy > src_gl->cellused)
|
|
||||||
to_copy = src_gl->cellused;
|
|
||||||
|
|
||||||
/* Expand destination line. */
|
|
||||||
dst_gl->celldata = xreallocarray(NULL, to_copy,
|
|
||||||
sizeof *dst_gl->celldata);
|
|
||||||
dst_gl->cellsize = dst_gl->cellused = to_copy;
|
|
||||||
dst_gl->flags |= GRID_LINE_WRAPPED;
|
|
||||||
|
|
||||||
/* Copy the data. */
|
|
||||||
grid_reflow_copy(dst_gl, 0, src_gl, offset, to_copy);
|
|
||||||
|
|
||||||
/* Move offset and reduce old line size. */
|
|
||||||
offset += to_copy;
|
|
||||||
src_gl->cellused -= to_copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Last line is not wrapped. */
|
|
||||||
if (dst_gl != NULL)
|
|
||||||
dst_gl->flags &= ~GRID_LINE_WRAPPED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move line data. */
|
|
||||||
static void
|
|
||||||
grid_reflow_move(struct grid *dst, u_int *py, struct grid_line *src_gl)
|
|
||||||
{
|
|
||||||
struct grid_line *dst_gl;
|
|
||||||
|
|
||||||
/* Create new line. */
|
|
||||||
if (*py >= dst->hsize + dst->sy)
|
|
||||||
grid_scroll_history(dst, 8);
|
|
||||||
dst_gl = &dst->linedata[*py];
|
|
||||||
(*py)++;
|
|
||||||
|
|
||||||
/* Copy the old line. */
|
|
||||||
memcpy(dst_gl, src_gl, sizeof *dst_gl);
|
|
||||||
dst_gl->flags &= ~GRID_LINE_WRAPPED;
|
|
||||||
|
|
||||||
/* Clear old line. */
|
|
||||||
src_gl->celldata = NULL;
|
|
||||||
src_gl->extddata = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reflow lines from src grid into dst grid of width new_x. Returns number of
|
|
||||||
* lines fewer in the visible area. The source grid is destroyed.
|
|
||||||
*/
|
|
||||||
u_int
|
|
||||||
grid_reflow(struct grid *dst, struct grid *src, u_int new_x)
|
|
||||||
{
|
|
||||||
u_int py, sy, line;
|
|
||||||
int previous_wrapped;
|
|
||||||
struct grid_line *src_gl;
|
|
||||||
|
|
||||||
py = 0;
|
|
||||||
sy = src->sy;
|
|
||||||
|
|
||||||
previous_wrapped = 0;
|
|
||||||
for (line = 0; line < sy + src->hsize; line++) {
|
|
||||||
src_gl = src->linedata + line;
|
|
||||||
if (!previous_wrapped) {
|
|
||||||
/* Wasn't wrapped. If smaller, move to destination. */
|
|
||||||
if (src_gl->cellused <= new_x)
|
|
||||||
grid_reflow_move(dst, &py, src_gl);
|
|
||||||
else
|
|
||||||
grid_reflow_split(dst, &py, src_gl, new_x, 0);
|
|
||||||
} else {
|
|
||||||
/* Previous was wrapped. Try to join. */
|
|
||||||
grid_reflow_join(dst, &py, src_gl, new_x);
|
|
||||||
}
|
}
|
||||||
previous_wrapped = (src_gl->flags & GRID_LINE_WRAPPED);
|
|
||||||
|
|
||||||
/* This is where we started scrolling. */
|
/*
|
||||||
if (line == sy + src->hsize - src->hscrolled - 1)
|
* Is the destination line now full? Copy the first character
|
||||||
dst->hscrolled = 0;
|
* separately because we need to leave "from" set to the last
|
||||||
|
* line if this line is full.
|
||||||
|
*/
|
||||||
|
grid_get_cell1(&gd->linedata[line], 0, &gc);
|
||||||
|
if (width + gc.data.width > sx)
|
||||||
|
break;
|
||||||
|
width += gc.data.width;
|
||||||
|
grid_set_cell(target, at, to, &gc);
|
||||||
|
at++;
|
||||||
|
|
||||||
|
/* Join as much more as possible onto the current line. */
|
||||||
|
from = &gd->linedata[line];
|
||||||
|
for (want = 1; want < from->cellused; want++) {
|
||||||
|
grid_get_cell1(from, want, &gc);
|
||||||
|
if (width + gc.data.width > sx)
|
||||||
|
break;
|
||||||
|
width += gc.data.width;
|
||||||
|
|
||||||
|
grid_set_cell(target, at, to, &gc);
|
||||||
|
at++;
|
||||||
|
}
|
||||||
|
lines++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If this line wasn't wrapped or we didn't consume the entire
|
||||||
|
* line, don't try to join any further lines.
|
||||||
|
*/
|
||||||
|
if (!wrapped || want != from->cellused || width == sx)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (lines == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we didn't consume the entire final line, then remove what we did
|
||||||
|
* consume. If we consumed the entire line and it wasn't wrapped,
|
||||||
|
* remove the wrap flag from this line.
|
||||||
|
*/
|
||||||
|
left = from->cellused - want;
|
||||||
|
if (left != 0) {
|
||||||
|
grid_move_cells(gd, 0, want, yy + lines, left, 8);
|
||||||
|
from->cellsize = from->cellused = left;
|
||||||
|
lines--;
|
||||||
|
} else if (!wrapped)
|
||||||
|
gl->flags &= ~GRID_LINE_WRAPPED;
|
||||||
|
|
||||||
|
/* Remove the lines that were completely consumed. */
|
||||||
|
for (i = yy + 1; i < yy + 1 + lines; i++) {
|
||||||
|
free(gd->linedata[i].celldata);
|
||||||
|
free(gd->linedata[i].extddata);
|
||||||
|
grid_reflow_dead(&gd->linedata[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
grid_destroy(src);
|
/* Adjust cursor and scroll positions. */
|
||||||
|
if (*cy > to + lines)
|
||||||
if (py > sy)
|
*cy -= lines;
|
||||||
return (0);
|
else if (*cy > to)
|
||||||
return (sy - py);
|
*cy = to;
|
||||||
|
if (gd->hscrolled > to + lines)
|
||||||
|
gd->hscrolled -= lines;
|
||||||
|
else if (gd->hscrolled > to)
|
||||||
|
gd->hscrolled = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Split this line into several new ones */
|
||||||
|
static void
|
||||||
|
grid_reflow_split(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||||
|
u_int at, u_int *cy)
|
||||||
|
{
|
||||||
|
struct grid_line *gl = &gd->linedata[yy], *first;
|
||||||
|
struct grid_cell gc;
|
||||||
|
u_int line, lines, width, i, xx;
|
||||||
|
u_int used = gl->cellused;
|
||||||
|
int flags = gl->flags;
|
||||||
|
|
||||||
|
/* How many lines do we need to insert? We know we need at least two. */
|
||||||
|
if (~gl->flags & GRID_LINE_EXTENDED)
|
||||||
|
lines = 1 + (gl->cellused - 1) / sx;
|
||||||
|
else {
|
||||||
|
lines = 2;
|
||||||
|
width = 0;
|
||||||
|
for (i = at; i < used; i++) {
|
||||||
|
grid_get_cell1(gl, i, &gc);
|
||||||
|
if (width + gc.data.width > sx) {
|
||||||
|
lines++;
|
||||||
|
width = 0;
|
||||||
|
}
|
||||||
|
width += gc.data.width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Insert new lines. */
|
||||||
|
line = target->sy + 1;
|
||||||
|
first = grid_reflow_add(target, lines);
|
||||||
|
|
||||||
|
/* Copy sections from the original line. */
|
||||||
|
width = 0;
|
||||||
|
xx = 0;
|
||||||
|
for (i = at; i < used; i++) {
|
||||||
|
grid_get_cell1(gl, i, &gc);
|
||||||
|
if (width + gc.data.width > sx) {
|
||||||
|
target->linedata[line].flags |= GRID_LINE_WRAPPED;
|
||||||
|
|
||||||
|
line++;
|
||||||
|
width = 0;
|
||||||
|
xx = 0;
|
||||||
|
}
|
||||||
|
width += gc.data.width;
|
||||||
|
grid_set_cell(target, xx, line, &gc);
|
||||||
|
xx++;
|
||||||
|
}
|
||||||
|
if (flags & GRID_LINE_WRAPPED)
|
||||||
|
target->linedata[line].flags |= GRID_LINE_WRAPPED;
|
||||||
|
|
||||||
|
/* Move the remainder of the original line. */
|
||||||
|
gl->cellsize = gl->cellused = at;
|
||||||
|
gl->flags |= GRID_LINE_WRAPPED;
|
||||||
|
memcpy(first, gl, sizeof *first);
|
||||||
|
grid_reflow_dead(gl);
|
||||||
|
|
||||||
|
/* Adjust the cursor and scroll positions. */
|
||||||
|
if (yy <= *cy)
|
||||||
|
(*cy) += lines - 1;
|
||||||
|
if (yy <= gd->hscrolled)
|
||||||
|
gd->hscrolled += lines - 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the original line had the wrapped flag and there is still space
|
||||||
|
* in the last new line, try to join with the next lines.
|
||||||
|
*/
|
||||||
|
if (width < sx && (flags & GRID_LINE_WRAPPED))
|
||||||
|
grid_reflow_join(target, gd, sx, yy, width, cy, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reflow lines on grid to new width. */
|
||||||
|
void
|
||||||
|
grid_reflow(struct grid *gd, u_int sx, u_int *cursor)
|
||||||
|
{
|
||||||
|
struct grid *target;
|
||||||
|
struct grid_line *gl;
|
||||||
|
struct grid_cell gc;
|
||||||
|
u_int yy, cy, width, i, at, first;
|
||||||
|
struct timeval start, tv;
|
||||||
|
|
||||||
|
gettimeofday(&start, NULL);
|
||||||
|
|
||||||
|
log_debug("%s: %u lines, new width %u", __func__, gd->hsize + gd->sy,
|
||||||
|
sx);
|
||||||
|
cy = gd->hsize + (*cursor);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a destination grid. This is just used as a container for the
|
||||||
|
* line data and may not be fully valid.
|
||||||
|
*/
|
||||||
|
target = grid_create(gd->sx, 0, 0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loop over each source line.
|
||||||
|
*/
|
||||||
|
for (yy = 0; yy < gd->hsize + gd->sy; yy++) {
|
||||||
|
gl = &gd->linedata[yy];
|
||||||
|
if (gl->flags & GRID_LINE_DEAD)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Work out the width of this line. first is the width of the
|
||||||
|
* first character, at is the point at which the available
|
||||||
|
* width is hit, and width is the full line width.
|
||||||
|
*/
|
||||||
|
first = at = width = 0;
|
||||||
|
if (~gl->flags & GRID_LINE_EXTENDED) {
|
||||||
|
first = 1;
|
||||||
|
width = gl->cellused;
|
||||||
|
if (width > sx)
|
||||||
|
at = sx;
|
||||||
|
else
|
||||||
|
at = width;
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < gl->cellused; i++) {
|
||||||
|
grid_get_cell1(gl, i, &gc);
|
||||||
|
if (i == 0)
|
||||||
|
first = gc.data.width;
|
||||||
|
if (at == 0 && width + gc.data.width > sx)
|
||||||
|
at = i;
|
||||||
|
width += gc.data.width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the line is exactly right or the first character is wider
|
||||||
|
* than the targe width, just move it across unchanged.
|
||||||
|
*/
|
||||||
|
if (width == sx || first > sx) {
|
||||||
|
grid_reflow_move(target, gl);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the line is too big, it needs to be split, whether or not
|
||||||
|
* it was previously wrapped.
|
||||||
|
*/
|
||||||
|
if (width > sx) {
|
||||||
|
grid_reflow_split(target, gd, sx, yy, at, &cy);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the line was previously wrapped, join as much as possible
|
||||||
|
* of the next line.
|
||||||
|
*/
|
||||||
|
if (gl->flags & GRID_LINE_WRAPPED)
|
||||||
|
grid_reflow_join(target, gd, sx, yy, width, &cy, 0);
|
||||||
|
else
|
||||||
|
grid_reflow_move(target, gl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Replace the old grid with the new.
|
||||||
|
*/
|
||||||
|
if (target->sy < gd->sy)
|
||||||
|
grid_reflow_add(target, gd->sy - target->sy);
|
||||||
|
gd->hsize = target->sy - gd->sy;
|
||||||
|
free(gd->linedata);
|
||||||
|
gd->linedata = target->linedata;
|
||||||
|
free(target);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Update scrolled and cursor positions.
|
||||||
|
*/
|
||||||
|
if (gd->hscrolled > gd->hsize)
|
||||||
|
gd->hscrolled = gd->hsize;
|
||||||
|
if (cy < gd->hsize)
|
||||||
|
*cursor = 0;
|
||||||
|
else
|
||||||
|
*cursor = cy - gd->hsize;
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
timersub(&tv, &start, &tv);
|
||||||
|
log_debug("%s: now %u lines (in %llu.%06u seconds)", __func__,
|
||||||
|
gd->hsize + gd->sy, (unsigned long long)tv.tv_sec,
|
||||||
|
(u_int)tv.tv_usec);
|
||||||
}
|
}
|
||||||
|
|||||||
27
hooks.c
27
hooks.c
@@ -139,33 +139,6 @@ hooks_find(struct hooks *hooks, const char *name)
|
|||||||
return (hook);
|
return (hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs,
|
|
||||||
const char *fmt, ...)
|
|
||||||
{
|
|
||||||
struct hook *hook;
|
|
||||||
va_list ap;
|
|
||||||
char *name;
|
|
||||||
struct cmdq_item *new_item;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
xvasprintf(&name, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
hook = hooks_find(hooks, name);
|
|
||||||
if (hook == NULL) {
|
|
||||||
free(name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
log_debug("running hook %s", name);
|
|
||||||
|
|
||||||
new_item = cmdq_get_command(hook->cmdlist, fs, NULL, CMDQ_NOHOOKS);
|
|
||||||
cmdq_format(new_item, "hook", "%s", name);
|
|
||||||
cmdq_append(c, new_item);
|
|
||||||
|
|
||||||
free(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
hooks_insert(struct hooks *hooks, struct cmdq_item *item,
|
hooks_insert(struct hooks *hooks, struct cmdq_item *item,
|
||||||
struct cmd_find_state *fs, const char *fmt, ...)
|
struct cmd_find_state *fs, const char *fmt, ...)
|
||||||
|
|||||||
469
input.c
469
input.c
@@ -30,7 +30,7 @@
|
|||||||
/*
|
/*
|
||||||
* Based on the description by Paul Williams at:
|
* Based on the description by Paul Williams at:
|
||||||
*
|
*
|
||||||
* http://vt100.net/emu/dec_ansi_parser
|
* https://vt100.net/emu/dec_ansi_parser
|
||||||
*
|
*
|
||||||
* With the following changes:
|
* With the following changes:
|
||||||
*
|
*
|
||||||
@@ -58,6 +58,19 @@ struct input_cell {
|
|||||||
int g1set; /* 1 if ACS */
|
int g1set; /* 1 if ACS */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Input parser argument. */
|
||||||
|
struct input_param {
|
||||||
|
enum {
|
||||||
|
INPUT_MISSING,
|
||||||
|
INPUT_NUMBER,
|
||||||
|
INPUT_STRING
|
||||||
|
} type;
|
||||||
|
union {
|
||||||
|
int num;
|
||||||
|
char *str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/* Input parser context. */
|
/* Input parser context. */
|
||||||
struct input_ctx {
|
struct input_ctx {
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
@@ -81,10 +94,11 @@ struct input_ctx {
|
|||||||
size_t input_len;
|
size_t input_len;
|
||||||
size_t input_space;
|
size_t input_space;
|
||||||
|
|
||||||
int param_list[24]; /* -1 not present */
|
struct input_param param_list[24];
|
||||||
u_int param_list_len;
|
u_int param_list_len;
|
||||||
|
|
||||||
struct utf8_data utf8data;
|
struct utf8_data utf8data;
|
||||||
|
int utf8started;
|
||||||
|
|
||||||
int ch;
|
int ch;
|
||||||
int last;
|
int last;
|
||||||
@@ -146,9 +160,7 @@ static void input_csi_dispatch_sgr_256(struct input_ctx *, int, u_int *);
|
|||||||
static void input_csi_dispatch_sgr_rgb(struct input_ctx *, int, u_int *);
|
static void input_csi_dispatch_sgr_rgb(struct input_ctx *, int, u_int *);
|
||||||
static void input_csi_dispatch_sgr(struct input_ctx *);
|
static void input_csi_dispatch_sgr(struct input_ctx *);
|
||||||
static int input_dcs_dispatch(struct input_ctx *);
|
static int input_dcs_dispatch(struct input_ctx *);
|
||||||
static int input_utf8_open(struct input_ctx *);
|
static int input_top_bit_set(struct input_ctx *);
|
||||||
static int input_utf8_add(struct input_ctx *);
|
|
||||||
static int input_utf8_close(struct input_ctx *);
|
|
||||||
|
|
||||||
/* Command table comparison function. */
|
/* Command table comparison function. */
|
||||||
static int input_table_compare(const void *, const void *);
|
static int input_table_compare(const void *, const void *);
|
||||||
@@ -314,9 +326,6 @@ static const struct input_transition input_state_osc_string_table[];
|
|||||||
static const struct input_transition input_state_apc_string_table[];
|
static const struct input_transition input_state_apc_string_table[];
|
||||||
static const struct input_transition input_state_rename_string_table[];
|
static const struct input_transition input_state_rename_string_table[];
|
||||||
static const struct input_transition input_state_consume_st_table[];
|
static const struct input_transition input_state_consume_st_table[];
|
||||||
static const struct input_transition input_state_utf8_three_table[];
|
|
||||||
static const struct input_transition input_state_utf8_two_table[];
|
|
||||||
static const struct input_transition input_state_utf8_one_table[];
|
|
||||||
|
|
||||||
/* ground state definition. */
|
/* ground state definition. */
|
||||||
static const struct input_state input_state_ground = {
|
static const struct input_state input_state_ground = {
|
||||||
@@ -437,27 +446,6 @@ static const struct input_state input_state_consume_st = {
|
|||||||
input_state_consume_st_table
|
input_state_consume_st_table
|
||||||
};
|
};
|
||||||
|
|
||||||
/* utf8_three state definition. */
|
|
||||||
static const struct input_state input_state_utf8_three = {
|
|
||||||
"utf8_three",
|
|
||||||
NULL, NULL,
|
|
||||||
input_state_utf8_three_table
|
|
||||||
};
|
|
||||||
|
|
||||||
/* utf8_two state definition. */
|
|
||||||
static const struct input_state input_state_utf8_two = {
|
|
||||||
"utf8_two",
|
|
||||||
NULL, NULL,
|
|
||||||
input_state_utf8_two_table
|
|
||||||
};
|
|
||||||
|
|
||||||
/* utf8_one state definition. */
|
|
||||||
static const struct input_state input_state_utf8_one = {
|
|
||||||
"utf8_one",
|
|
||||||
NULL, NULL,
|
|
||||||
input_state_utf8_one_table
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ground state table. */
|
/* ground state table. */
|
||||||
static const struct input_transition input_state_ground_table[] = {
|
static const struct input_transition input_state_ground_table[] = {
|
||||||
INPUT_STATE_ANYWHERE,
|
INPUT_STATE_ANYWHERE,
|
||||||
@@ -467,11 +455,7 @@ static const struct input_transition input_state_ground_table[] = {
|
|||||||
{ 0x1c, 0x1f, input_c0_dispatch, NULL },
|
{ 0x1c, 0x1f, input_c0_dispatch, NULL },
|
||||||
{ 0x20, 0x7e, input_print, NULL },
|
{ 0x20, 0x7e, input_print, NULL },
|
||||||
{ 0x7f, 0x7f, NULL, NULL },
|
{ 0x7f, 0x7f, NULL, NULL },
|
||||||
{ 0x80, 0xc1, NULL, NULL },
|
{ 0x80, 0xff, input_top_bit_set, NULL },
|
||||||
{ 0xc2, 0xdf, input_utf8_open, &input_state_utf8_one },
|
|
||||||
{ 0xe0, 0xef, input_utf8_open, &input_state_utf8_two },
|
|
||||||
{ 0xf0, 0xf4, input_utf8_open, &input_state_utf8_three },
|
|
||||||
{ 0xf5, 0xff, NULL, NULL },
|
|
||||||
|
|
||||||
{ -1, -1, NULL, NULL }
|
{ -1, -1, NULL, NULL }
|
||||||
};
|
};
|
||||||
@@ -526,7 +510,7 @@ static const struct input_transition input_state_csi_enter_table[] = {
|
|||||||
{ 0x1c, 0x1f, input_c0_dispatch, NULL },
|
{ 0x1c, 0x1f, input_c0_dispatch, NULL },
|
||||||
{ 0x20, 0x2f, input_intermediate, &input_state_csi_intermediate },
|
{ 0x20, 0x2f, input_intermediate, &input_state_csi_intermediate },
|
||||||
{ 0x30, 0x39, input_parameter, &input_state_csi_parameter },
|
{ 0x30, 0x39, input_parameter, &input_state_csi_parameter },
|
||||||
{ 0x3a, 0x3a, NULL, &input_state_csi_ignore },
|
{ 0x3a, 0x3a, input_parameter, &input_state_csi_parameter },
|
||||||
{ 0x3b, 0x3b, input_parameter, &input_state_csi_parameter },
|
{ 0x3b, 0x3b, input_parameter, &input_state_csi_parameter },
|
||||||
{ 0x3c, 0x3f, input_intermediate, &input_state_csi_parameter },
|
{ 0x3c, 0x3f, input_intermediate, &input_state_csi_parameter },
|
||||||
{ 0x40, 0x7e, input_csi_dispatch, &input_state_ground },
|
{ 0x40, 0x7e, input_csi_dispatch, &input_state_ground },
|
||||||
@@ -544,7 +528,7 @@ static const struct input_transition input_state_csi_parameter_table[] = {
|
|||||||
{ 0x1c, 0x1f, input_c0_dispatch, NULL },
|
{ 0x1c, 0x1f, input_c0_dispatch, NULL },
|
||||||
{ 0x20, 0x2f, input_intermediate, &input_state_csi_intermediate },
|
{ 0x20, 0x2f, input_intermediate, &input_state_csi_intermediate },
|
||||||
{ 0x30, 0x39, input_parameter, NULL },
|
{ 0x30, 0x39, input_parameter, NULL },
|
||||||
{ 0x3a, 0x3a, NULL, &input_state_csi_ignore },
|
{ 0x3a, 0x3a, input_parameter, NULL },
|
||||||
{ 0x3b, 0x3b, input_parameter, NULL },
|
{ 0x3b, 0x3b, input_parameter, NULL },
|
||||||
{ 0x3c, 0x3f, NULL, &input_state_csi_ignore },
|
{ 0x3c, 0x3f, NULL, &input_state_csi_ignore },
|
||||||
{ 0x40, 0x7e, input_csi_dispatch, &input_state_ground },
|
{ 0x40, 0x7e, input_csi_dispatch, &input_state_ground },
|
||||||
@@ -717,39 +701,6 @@ static const struct input_transition input_state_consume_st_table[] = {
|
|||||||
{ -1, -1, NULL, NULL }
|
{ -1, -1, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* utf8_three state table. */
|
|
||||||
static const struct input_transition input_state_utf8_three_table[] = {
|
|
||||||
/* No INPUT_STATE_ANYWHERE */
|
|
||||||
|
|
||||||
{ 0x00, 0x7f, NULL, &input_state_ground },
|
|
||||||
{ 0x80, 0xbf, input_utf8_add, &input_state_utf8_two },
|
|
||||||
{ 0xc0, 0xff, NULL, &input_state_ground },
|
|
||||||
|
|
||||||
{ -1, -1, NULL, NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
/* utf8_two state table. */
|
|
||||||
static const struct input_transition input_state_utf8_two_table[] = {
|
|
||||||
/* No INPUT_STATE_ANYWHERE */
|
|
||||||
|
|
||||||
{ 0x00, 0x7f, NULL, &input_state_ground },
|
|
||||||
{ 0x80, 0xbf, input_utf8_add, &input_state_utf8_one },
|
|
||||||
{ 0xc0, 0xff, NULL, &input_state_ground },
|
|
||||||
|
|
||||||
{ -1, -1, NULL, NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
/* utf8_one state table. */
|
|
||||||
static const struct input_transition input_state_utf8_one_table[] = {
|
|
||||||
/* No INPUT_STATE_ANYWHERE */
|
|
||||||
|
|
||||||
{ 0x00, 0x7f, NULL, &input_state_ground },
|
|
||||||
{ 0x80, 0xbf, input_utf8_close, &input_state_ground },
|
|
||||||
{ 0xc0, 0xff, NULL, &input_state_ground },
|
|
||||||
|
|
||||||
{ -1, -1, NULL, NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Input table compare. */
|
/* Input table compare. */
|
||||||
static int
|
static int
|
||||||
input_table_compare(const void *key, const void *value)
|
input_table_compare(const void *key, const void *value)
|
||||||
@@ -822,6 +773,12 @@ void
|
|||||||
input_free(struct window_pane *wp)
|
input_free(struct window_pane *wp)
|
||||||
{
|
{
|
||||||
struct input_ctx *ictx = wp->ictx;
|
struct input_ctx *ictx = wp->ictx;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
for (i = 0; i < ictx->param_list_len; i++) {
|
||||||
|
if (ictx->param_list[i].type == INPUT_STRING)
|
||||||
|
free(ictx->param_list[i].str);
|
||||||
|
}
|
||||||
|
|
||||||
event_del(&ictx->timer);
|
event_del(&ictx->timer);
|
||||||
|
|
||||||
@@ -964,29 +921,51 @@ input_parse(struct window_pane *wp)
|
|||||||
static int
|
static int
|
||||||
input_split(struct input_ctx *ictx)
|
input_split(struct input_ctx *ictx)
|
||||||
{
|
{
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
char *ptr, *out;
|
char *ptr, *out;
|
||||||
int n;
|
struct input_param *ip;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
for (i = 0; i < ictx->param_list_len; i++) {
|
||||||
|
if (ictx->param_list[i].type == INPUT_STRING)
|
||||||
|
free(ictx->param_list[i].str);
|
||||||
|
}
|
||||||
ictx->param_list_len = 0;
|
ictx->param_list_len = 0;
|
||||||
|
|
||||||
if (ictx->param_len == 0)
|
if (ictx->param_len == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
ip = &ictx->param_list[0];
|
||||||
|
|
||||||
ptr = ictx->param_buf;
|
ptr = ictx->param_buf;
|
||||||
while ((out = strsep(&ptr, ";")) != NULL) {
|
while ((out = strsep(&ptr, ";")) != NULL) {
|
||||||
if (*out == '\0')
|
if (*out == '\0')
|
||||||
n = -1;
|
ip->type = INPUT_MISSING;
|
||||||
else {
|
else {
|
||||||
n = strtonum(out, 0, INT_MAX, &errstr);
|
if (strchr(out, ':') != NULL) {
|
||||||
if (errstr != NULL)
|
ip->type = INPUT_STRING;
|
||||||
return (-1);
|
ip->str = xstrdup(out);
|
||||||
|
} else {
|
||||||
|
ip->type = INPUT_NUMBER;
|
||||||
|
ip->num = strtonum(out, 0, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ip = &ictx->param_list[++ictx->param_list_len];
|
||||||
ictx->param_list[ictx->param_list_len++] = n;
|
|
||||||
if (ictx->param_list_len == nitems(ictx->param_list))
|
if (ictx->param_list_len == nitems(ictx->param_list))
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < ictx->param_list_len; i++) {
|
||||||
|
ip = &ictx->param_list[i];
|
||||||
|
if (ip->type == INPUT_MISSING)
|
||||||
|
log_debug("parameter %u: missing", i);
|
||||||
|
else if (ip->type == INPUT_STRING)
|
||||||
|
log_debug("parameter %u: string %s", i, ip->str);
|
||||||
|
else if (ip->type == INPUT_NUMBER)
|
||||||
|
log_debug("parameter %u: number %d", i, ip->num);
|
||||||
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -994,14 +973,17 @@ input_split(struct input_ctx *ictx)
|
|||||||
static int
|
static int
|
||||||
input_get(struct input_ctx *ictx, u_int validx, int minval, int defval)
|
input_get(struct input_ctx *ictx, u_int validx, int minval, int defval)
|
||||||
{
|
{
|
||||||
int retval;
|
struct input_param *ip;
|
||||||
|
int retval;
|
||||||
|
|
||||||
if (validx >= ictx->param_list_len)
|
if (validx >= ictx->param_list_len)
|
||||||
return (defval);
|
return (defval);
|
||||||
|
ip = &ictx->param_list[validx];
|
||||||
retval = ictx->param_list[validx];
|
if (ip->type == INPUT_MISSING)
|
||||||
if (retval == -1)
|
|
||||||
return (defval);
|
return (defval);
|
||||||
|
if (ip->type == INPUT_STRING)
|
||||||
|
return (-1);
|
||||||
|
retval = ip->num;
|
||||||
if (retval < minval)
|
if (retval < minval)
|
||||||
return (minval);
|
return (minval);
|
||||||
return (retval);
|
return (retval);
|
||||||
@@ -1059,6 +1041,8 @@ input_print(struct input_ctx *ictx)
|
|||||||
{
|
{
|
||||||
int set;
|
int set;
|
||||||
|
|
||||||
|
ictx->utf8started = 0; /* can't be valid UTF-8 */
|
||||||
|
|
||||||
set = ictx->cell.set == 0 ? ictx->cell.g0set : ictx->cell.g1set;
|
set = ictx->cell.set == 0 ? ictx->cell.g0set : ictx->cell.g1set;
|
||||||
if (set == 1)
|
if (set == 1)
|
||||||
ictx->cell.cell.attr |= GRID_ATTR_CHARSET;
|
ictx->cell.cell.attr |= GRID_ATTR_CHARSET;
|
||||||
@@ -1132,6 +1116,8 @@ input_c0_dispatch(struct input_ctx *ictx)
|
|||||||
struct window_pane *wp = ictx->wp;
|
struct window_pane *wp = ictx->wp;
|
||||||
struct screen *s = sctx->s;
|
struct screen *s = sctx->s;
|
||||||
|
|
||||||
|
ictx->utf8started = 0; /* can't be valid UTF-8 */
|
||||||
|
|
||||||
log_debug("%s: '%c'", __func__, ictx->ch);
|
log_debug("%s: '%c'", __func__, ictx->ch);
|
||||||
|
|
||||||
switch (ictx->ch) {
|
switch (ictx->ch) {
|
||||||
@@ -1202,6 +1188,7 @@ input_esc_dispatch(struct input_ctx *ictx)
|
|||||||
window_pane_reset_palette(ictx->wp);
|
window_pane_reset_palette(ictx->wp);
|
||||||
input_reset_cell(ictx);
|
input_reset_cell(ictx);
|
||||||
screen_write_reset(sctx);
|
screen_write_reset(sctx);
|
||||||
|
screen_write_clearhistory(sctx);
|
||||||
break;
|
break;
|
||||||
case INPUT_ESC_IND:
|
case INPUT_ESC_IND:
|
||||||
screen_write_linefeed(sctx, 0, ictx->cell.cell.bg);
|
screen_write_linefeed(sctx, 0, ictx->cell.cell.bg);
|
||||||
@@ -1264,7 +1251,7 @@ input_csi_dispatch(struct input_ctx *ictx)
|
|||||||
struct screen *s = sctx->s;
|
struct screen *s = sctx->s;
|
||||||
struct input_table_entry *entry;
|
struct input_table_entry *entry;
|
||||||
int i, n, m;
|
int i, n, m;
|
||||||
u_int cx;
|
u_int cx, bg = ictx->cell.cell.bg;
|
||||||
|
|
||||||
if (ictx->flags & INPUT_DISCARD)
|
if (ictx->flags & INPUT_DISCARD)
|
||||||
return (0);
|
return (0);
|
||||||
@@ -1289,6 +1276,8 @@ input_csi_dispatch(struct input_ctx *ictx)
|
|||||||
if (cx > screen_size_x(s) - 1)
|
if (cx > screen_size_x(s) - 1)
|
||||||
cx = screen_size_x(s) - 1;
|
cx = screen_size_x(s) - 1;
|
||||||
n = input_get(ictx, 0, 1, 1);
|
n = input_get(ictx, 0, 1, 1);
|
||||||
|
if (n == -1)
|
||||||
|
break;
|
||||||
while (cx > 0 && n-- > 0) {
|
while (cx > 0 && n-- > 0) {
|
||||||
do
|
do
|
||||||
cx--;
|
cx--;
|
||||||
@@ -1297,35 +1286,52 @@ input_csi_dispatch(struct input_ctx *ictx)
|
|||||||
s->cx = cx;
|
s->cx = cx;
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_CUB:
|
case INPUT_CSI_CUB:
|
||||||
screen_write_cursorleft(sctx, input_get(ictx, 0, 1, 1));
|
n = input_get(ictx, 0, 1, 1);
|
||||||
|
if (n != -1)
|
||||||
|
screen_write_cursorleft(sctx, n);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_CUD:
|
case INPUT_CSI_CUD:
|
||||||
screen_write_cursordown(sctx, input_get(ictx, 0, 1, 1));
|
n = input_get(ictx, 0, 1, 1);
|
||||||
|
if (n != -1)
|
||||||
|
screen_write_cursordown(sctx, n);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_CUF:
|
case INPUT_CSI_CUF:
|
||||||
screen_write_cursorright(sctx, input_get(ictx, 0, 1, 1));
|
n = input_get(ictx, 0, 1, 1);
|
||||||
|
if (n != -1)
|
||||||
|
screen_write_cursorright(sctx, n);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_CUP:
|
case INPUT_CSI_CUP:
|
||||||
n = input_get(ictx, 0, 1, 1);
|
n = input_get(ictx, 0, 1, 1);
|
||||||
m = input_get(ictx, 1, 1, 1);
|
m = input_get(ictx, 1, 1, 1);
|
||||||
screen_write_cursormove(sctx, m - 1, n - 1);
|
if (n != -1 && m != -1)
|
||||||
|
screen_write_cursormove(sctx, m - 1, n - 1);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_WINOPS:
|
case INPUT_CSI_WINOPS:
|
||||||
input_csi_dispatch_winops(ictx);
|
input_csi_dispatch_winops(ictx);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_CUU:
|
case INPUT_CSI_CUU:
|
||||||
screen_write_cursorup(sctx, input_get(ictx, 0, 1, 1));
|
n = input_get(ictx, 0, 1, 1);
|
||||||
|
if (n != -1)
|
||||||
|
screen_write_cursorup(sctx, n);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_CNL:
|
case INPUT_CSI_CNL:
|
||||||
screen_write_carriagereturn(sctx);
|
n = input_get(ictx, 0, 1, 1);
|
||||||
screen_write_cursordown(sctx, input_get(ictx, 0, 1, 1));
|
if (n != -1) {
|
||||||
|
screen_write_carriagereturn(sctx);
|
||||||
|
screen_write_cursordown(sctx, n);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_CPL:
|
case INPUT_CSI_CPL:
|
||||||
screen_write_carriagereturn(sctx);
|
n = input_get(ictx, 0, 1, 1);
|
||||||
screen_write_cursorup(sctx, input_get(ictx, 0, 1, 1));
|
if (n != -1) {
|
||||||
|
screen_write_carriagereturn(sctx);
|
||||||
|
screen_write_cursorup(sctx, n);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_DA:
|
case INPUT_CSI_DA:
|
||||||
switch (input_get(ictx, 0, 0, 0)) {
|
switch (input_get(ictx, 0, 0, 0)) {
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
input_reply(ictx, "\033[?1;2c");
|
input_reply(ictx, "\033[?1;2c");
|
||||||
break;
|
break;
|
||||||
@@ -1336,6 +1342,8 @@ input_csi_dispatch(struct input_ctx *ictx)
|
|||||||
break;
|
break;
|
||||||
case INPUT_CSI_DA_TWO:
|
case INPUT_CSI_DA_TWO:
|
||||||
switch (input_get(ictx, 0, 0, 0)) {
|
switch (input_get(ictx, 0, 0, 0)) {
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
input_reply(ictx, "\033[>84;0;0c");
|
input_reply(ictx, "\033[>84;0;0c");
|
||||||
break;
|
break;
|
||||||
@@ -1345,24 +1353,30 @@ input_csi_dispatch(struct input_ctx *ictx)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_ECH:
|
case INPUT_CSI_ECH:
|
||||||
screen_write_clearcharacter(sctx, input_get(ictx, 0, 1, 1),
|
n = input_get(ictx, 0, 1, 1);
|
||||||
ictx->cell.cell.bg);
|
if (n != -1)
|
||||||
|
screen_write_clearcharacter(sctx, n, bg);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_DCH:
|
case INPUT_CSI_DCH:
|
||||||
screen_write_deletecharacter(sctx, input_get(ictx, 0, 1, 1),
|
n = input_get(ictx, 0, 1, 1);
|
||||||
ictx->cell.cell.bg);
|
if (n != -1)
|
||||||
|
screen_write_deletecharacter(sctx, n, bg);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_DECSTBM:
|
case INPUT_CSI_DECSTBM:
|
||||||
n = input_get(ictx, 0, 1, 1);
|
n = input_get(ictx, 0, 1, 1);
|
||||||
m = input_get(ictx, 1, 1, screen_size_y(s));
|
m = input_get(ictx, 1, 1, screen_size_y(s));
|
||||||
screen_write_scrollregion(sctx, n - 1, m - 1);
|
if (n != -1 && m != -1)
|
||||||
|
screen_write_scrollregion(sctx, n - 1, m - 1);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_DL:
|
case INPUT_CSI_DL:
|
||||||
screen_write_deleteline(sctx, input_get(ictx, 0, 1, 1),
|
n = input_get(ictx, 0, 1, 1);
|
||||||
ictx->cell.cell.bg);
|
if (n != -1)
|
||||||
|
screen_write_deleteline(sctx, n, bg);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_DSR:
|
case INPUT_CSI_DSR:
|
||||||
switch (input_get(ictx, 0, 0, 0)) {
|
switch (input_get(ictx, 0, 0, 0)) {
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
input_reply(ictx, "\033[0n");
|
input_reply(ictx, "\033[0n");
|
||||||
break;
|
break;
|
||||||
@@ -1376,24 +1390,24 @@ input_csi_dispatch(struct input_ctx *ictx)
|
|||||||
break;
|
break;
|
||||||
case INPUT_CSI_ED:
|
case INPUT_CSI_ED:
|
||||||
switch (input_get(ictx, 0, 0, 0)) {
|
switch (input_get(ictx, 0, 0, 0)) {
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
screen_write_clearendofscreen(sctx, ictx->cell.cell.bg);
|
screen_write_clearendofscreen(sctx, bg);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
screen_write_clearstartofscreen(sctx, ictx->cell.cell.bg);
|
screen_write_clearstartofscreen(sctx, bg);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
screen_write_clearscreen(sctx, ictx->cell.cell.bg);
|
screen_write_clearscreen(sctx, bg);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
switch (input_get(ictx, 1, 0, 0)) {
|
if (input_get(ictx, 1, 0, 0) == 0) {
|
||||||
case 0:
|
|
||||||
/*
|
/*
|
||||||
* Linux console extension to clear history
|
* Linux console extension to clear history
|
||||||
* (for example before locking the screen).
|
* (for example before locking the screen).
|
||||||
*/
|
*/
|
||||||
screen_write_clearhistory(sctx);
|
screen_write_clearhistory(sctx);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -1403,14 +1417,16 @@ input_csi_dispatch(struct input_ctx *ictx)
|
|||||||
break;
|
break;
|
||||||
case INPUT_CSI_EL:
|
case INPUT_CSI_EL:
|
||||||
switch (input_get(ictx, 0, 0, 0)) {
|
switch (input_get(ictx, 0, 0, 0)) {
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
screen_write_clearendofline(sctx, ictx->cell.cell.bg);
|
screen_write_clearendofline(sctx, bg);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
screen_write_clearstartofline(sctx, ictx->cell.cell.bg);
|
screen_write_clearstartofline(sctx, bg);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
screen_write_clearline(sctx, ictx->cell.cell.bg);
|
screen_write_clearline(sctx, bg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log_debug("%s: unknown '%c'", __func__, ictx->ch);
|
log_debug("%s: unknown '%c'", __func__, ictx->ch);
|
||||||
@@ -1419,22 +1435,28 @@ input_csi_dispatch(struct input_ctx *ictx)
|
|||||||
break;
|
break;
|
||||||
case INPUT_CSI_HPA:
|
case INPUT_CSI_HPA:
|
||||||
n = input_get(ictx, 0, 1, 1);
|
n = input_get(ictx, 0, 1, 1);
|
||||||
screen_write_cursormove(sctx, n - 1, s->cy);
|
if (n != -1)
|
||||||
|
screen_write_cursormove(sctx, n - 1, s->cy);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_ICH:
|
case INPUT_CSI_ICH:
|
||||||
screen_write_insertcharacter(sctx, input_get(ictx, 0, 1, 1),
|
n = input_get(ictx, 0, 1, 1);
|
||||||
ictx->cell.cell.bg);
|
if (n != -1)
|
||||||
|
screen_write_insertcharacter(sctx, n, bg);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_IL:
|
case INPUT_CSI_IL:
|
||||||
screen_write_insertline(sctx, input_get(ictx, 0, 1, 1),
|
n = input_get(ictx, 0, 1, 1);
|
||||||
ictx->cell.cell.bg);
|
if (n != -1)
|
||||||
|
screen_write_insertline(sctx, n, bg);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_REP:
|
case INPUT_CSI_REP:
|
||||||
|
n = input_get(ictx, 0, 1, 1);
|
||||||
|
if (n == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
if (ictx->last == -1)
|
if (ictx->last == -1)
|
||||||
break;
|
break;
|
||||||
ictx->ch = ictx->last;
|
ictx->ch = ictx->last;
|
||||||
|
|
||||||
n = input_get(ictx, 0, 1, 1);
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
input_print(ictx);
|
input_print(ictx);
|
||||||
break;
|
break;
|
||||||
@@ -1463,11 +1485,14 @@ input_csi_dispatch(struct input_ctx *ictx)
|
|||||||
input_csi_dispatch_sm_private(ictx);
|
input_csi_dispatch_sm_private(ictx);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_SU:
|
case INPUT_CSI_SU:
|
||||||
screen_write_scrollup(sctx, input_get(ictx, 0, 1, 1),
|
n = input_get(ictx, 0, 1, 1);
|
||||||
ictx->cell.cell.bg);
|
if (n != -1)
|
||||||
|
screen_write_scrollup(sctx, n, bg);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_TBC:
|
case INPUT_CSI_TBC:
|
||||||
switch (input_get(ictx, 0, 0, 0)) {
|
switch (input_get(ictx, 0, 0, 0)) {
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
if (s->cx < screen_size_x(s))
|
if (s->cx < screen_size_x(s))
|
||||||
bit_clear(s->tabs, s->cx);
|
bit_clear(s->tabs, s->cx);
|
||||||
@@ -1482,11 +1507,13 @@ input_csi_dispatch(struct input_ctx *ictx)
|
|||||||
break;
|
break;
|
||||||
case INPUT_CSI_VPA:
|
case INPUT_CSI_VPA:
|
||||||
n = input_get(ictx, 0, 1, 1);
|
n = input_get(ictx, 0, 1, 1);
|
||||||
screen_write_cursormove(sctx, s->cx, n - 1);
|
if (n != -1)
|
||||||
|
screen_write_cursormove(sctx, s->cx, n - 1);
|
||||||
break;
|
break;
|
||||||
case INPUT_CSI_DECSCUSR:
|
case INPUT_CSI_DECSCUSR:
|
||||||
n = input_get(ictx, 0, 0, 0);
|
n = input_get(ictx, 0, 0, 0);
|
||||||
screen_set_cursor_style(s, n);
|
if (n != -1)
|
||||||
|
screen_set_cursor_style(s, n);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1502,6 +1529,8 @@ input_csi_dispatch_rm(struct input_ctx *ictx)
|
|||||||
|
|
||||||
for (i = 0; i < ictx->param_list_len; i++) {
|
for (i = 0; i < ictx->param_list_len; i++) {
|
||||||
switch (input_get(ictx, i, 0, -1)) {
|
switch (input_get(ictx, i, 0, -1)) {
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
case 4: /* IRM */
|
case 4: /* IRM */
|
||||||
screen_write_mode_clear(&ictx->ctx, MODE_INSERT);
|
screen_write_mode_clear(&ictx->ctx, MODE_INSERT);
|
||||||
break;
|
break;
|
||||||
@@ -1524,6 +1553,8 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx)
|
|||||||
|
|
||||||
for (i = 0; i < ictx->param_list_len; i++) {
|
for (i = 0; i < ictx->param_list_len; i++) {
|
||||||
switch (input_get(ictx, i, 0, -1)) {
|
switch (input_get(ictx, i, 0, -1)) {
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
case 1: /* DECCKM */
|
case 1: /* DECCKM */
|
||||||
screen_write_mode_clear(&ictx->ctx, MODE_KCURSOR);
|
screen_write_mode_clear(&ictx->ctx, MODE_KCURSOR);
|
||||||
break;
|
break;
|
||||||
@@ -1581,6 +1612,8 @@ input_csi_dispatch_sm(struct input_ctx *ictx)
|
|||||||
|
|
||||||
for (i = 0; i < ictx->param_list_len; i++) {
|
for (i = 0; i < ictx->param_list_len; i++) {
|
||||||
switch (input_get(ictx, i, 0, -1)) {
|
switch (input_get(ictx, i, 0, -1)) {
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
case 4: /* IRM */
|
case 4: /* IRM */
|
||||||
screen_write_mode_set(&ictx->ctx, MODE_INSERT);
|
screen_write_mode_set(&ictx->ctx, MODE_INSERT);
|
||||||
break;
|
break;
|
||||||
@@ -1603,6 +1636,8 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
|
|||||||
|
|
||||||
for (i = 0; i < ictx->param_list_len; i++) {
|
for (i = 0; i < ictx->param_list_len; i++) {
|
||||||
switch (input_get(ictx, i, 0, -1)) {
|
switch (input_get(ictx, i, 0, -1)) {
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
case 1: /* DECCKM */
|
case 1: /* DECCKM */
|
||||||
screen_write_mode_set(&ictx->ctx, MODE_KCURSOR);
|
screen_write_mode_set(&ictx->ctx, MODE_KCURSOR);
|
||||||
break;
|
break;
|
||||||
@@ -1693,12 +1728,33 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
|
|||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case 9:
|
case 9:
|
||||||
case 10:
|
case 10:
|
||||||
case 22:
|
|
||||||
case 23:
|
|
||||||
m++;
|
m++;
|
||||||
if (input_get(ictx, m, 0, -1) == -1)
|
if (input_get(ictx, m, 0, -1) == -1)
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
|
case 22:
|
||||||
|
m++;
|
||||||
|
switch (input_get(ictx, m, 0, -1)) {
|
||||||
|
case -1:
|
||||||
|
return;
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
screen_push_title(ictx->ctx.s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 23:
|
||||||
|
m++;
|
||||||
|
switch (input_get(ictx, m, 0, -1)) {
|
||||||
|
case -1:
|
||||||
|
return;
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
screen_pop_title(ictx->ctx.s);
|
||||||
|
server_status_window(ictx->wp->window);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
input_reply(ictx, "\033[8;%u;%ut", wp->sy, wp->sx);
|
input_reply(ictx, "\033[8;%u;%ut", wp->sy, wp->sx);
|
||||||
break;
|
break;
|
||||||
@@ -1710,16 +1766,13 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle CSI SGR for 256 colours. */
|
/* Helper for 256 colour SGR. */
|
||||||
static void
|
static int
|
||||||
input_csi_dispatch_sgr_256(struct input_ctx *ictx, int fgbg, u_int *i)
|
input_csi_dispatch_sgr_256_do(struct input_ctx *ictx, int fgbg, int c)
|
||||||
{
|
{
|
||||||
struct grid_cell *gc = &ictx->cell.cell;
|
struct grid_cell *gc = &ictx->cell.cell;
|
||||||
int c;
|
|
||||||
|
|
||||||
(*i)++;
|
if (c == -1 || c > 255) {
|
||||||
c = input_get(ictx, *i, 0, -1);
|
|
||||||
if (c == -1) {
|
|
||||||
if (fgbg == 38)
|
if (fgbg == 38)
|
||||||
gc->fg = 8;
|
gc->fg = 8;
|
||||||
else if (fgbg == 48)
|
else if (fgbg == 48)
|
||||||
@@ -1730,32 +1783,99 @@ input_csi_dispatch_sgr_256(struct input_ctx *ictx, int fgbg, u_int *i)
|
|||||||
else if (fgbg == 48)
|
else if (fgbg == 48)
|
||||||
gc->bg = c | COLOUR_FLAG_256;
|
gc->bg = c | COLOUR_FLAG_256;
|
||||||
}
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Handle CSI SGR for 256 colours. */
|
||||||
|
static void
|
||||||
|
input_csi_dispatch_sgr_256(struct input_ctx *ictx, int fgbg, u_int *i)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
c = input_get(ictx, (*i) + 1, 0, -1);
|
||||||
|
if (input_csi_dispatch_sgr_256_do(ictx, fgbg, c))
|
||||||
|
(*i)++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Helper for RGB colour SGR. */
|
||||||
|
static int
|
||||||
|
input_csi_dispatch_sgr_rgb_do(struct input_ctx *ictx, int fgbg, int r, int g,
|
||||||
|
int b)
|
||||||
|
{
|
||||||
|
struct grid_cell *gc = &ictx->cell.cell;
|
||||||
|
|
||||||
|
if (r == -1 || r > 255)
|
||||||
|
return (0);
|
||||||
|
if (g == -1 || g > 255)
|
||||||
|
return (0);
|
||||||
|
if (b == -1 || b > 255)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (fgbg == 38)
|
||||||
|
gc->fg = colour_join_rgb(r, g, b);
|
||||||
|
else if (fgbg == 48)
|
||||||
|
gc->bg = colour_join_rgb(r, g, b);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle CSI SGR for RGB colours. */
|
/* Handle CSI SGR for RGB colours. */
|
||||||
static void
|
static void
|
||||||
input_csi_dispatch_sgr_rgb(struct input_ctx *ictx, int fgbg, u_int *i)
|
input_csi_dispatch_sgr_rgb(struct input_ctx *ictx, int fgbg, u_int *i)
|
||||||
{
|
{
|
||||||
struct grid_cell *gc = &ictx->cell.cell;
|
int r, g, b;
|
||||||
int r, g, b;
|
|
||||||
|
|
||||||
(*i)++;
|
r = input_get(ictx, (*i) + 1, 0, -1);
|
||||||
r = input_get(ictx, *i, 0, -1);
|
g = input_get(ictx, (*i) + 2, 0, -1);
|
||||||
if (r == -1 || r > 255)
|
b = input_get(ictx, (*i) + 3, 0, -1);
|
||||||
return;
|
if (input_csi_dispatch_sgr_rgb_do(ictx, fgbg, r, g, b))
|
||||||
(*i)++;
|
(*i) += 3;
|
||||||
g = input_get(ictx, *i, 0, -1);
|
}
|
||||||
if (g == -1 || g > 255)
|
|
||||||
return;
|
|
||||||
(*i)++;
|
|
||||||
b = input_get(ictx, *i, 0, -1);
|
|
||||||
if (b == -1 || b > 255)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (fgbg == 38)
|
/* Handle CSI SGR with a ISO parameter. */
|
||||||
gc->fg = colour_join_rgb(r, g, b);
|
static void
|
||||||
else if (fgbg == 48)
|
input_csi_dispatch_sgr_colon(struct input_ctx *ictx, u_int i)
|
||||||
gc->bg = colour_join_rgb(r, g, b);
|
{
|
||||||
|
char *s = ictx->param_list[i].str, *copy, *ptr, *out;
|
||||||
|
int p[8];
|
||||||
|
u_int n;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
|
for (n = 0; n < nitems(p); n++)
|
||||||
|
p[n] = -1;
|
||||||
|
n = 0;
|
||||||
|
|
||||||
|
ptr = copy = xstrdup(s);
|
||||||
|
while ((out = strsep(&ptr, ":")) != NULL) {
|
||||||
|
if (*out != '\0') {
|
||||||
|
p[n++] = strtonum(out, 0, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL || n == nitems(p)) {
|
||||||
|
free(copy);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_debug("%s: %u = %d", __func__, n - 1, p[n - 1]);
|
||||||
|
}
|
||||||
|
free(copy);
|
||||||
|
|
||||||
|
if (n == 0 || (p[0] != 38 && p[0] != 48))
|
||||||
|
return;
|
||||||
|
if (p[1] == -1)
|
||||||
|
i = 2;
|
||||||
|
else
|
||||||
|
i = 1;
|
||||||
|
switch (p[i]) {
|
||||||
|
case 2:
|
||||||
|
if (n < i + 4)
|
||||||
|
break;
|
||||||
|
input_csi_dispatch_sgr_rgb_do(ictx, p[0], p[i + 1], p[i + 2],
|
||||||
|
p[i + 3]);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
if (n < i + 2)
|
||||||
|
break;
|
||||||
|
input_csi_dispatch_sgr_256_do(ictx, p[0], p[i + 1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle CSI SGR. */
|
/* Handle CSI SGR. */
|
||||||
@@ -1772,7 +1892,13 @@ input_csi_dispatch_sgr(struct input_ctx *ictx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ictx->param_list_len; i++) {
|
for (i = 0; i < ictx->param_list_len; i++) {
|
||||||
|
if (ictx->param_list[i].type == INPUT_STRING) {
|
||||||
|
input_csi_dispatch_sgr_colon(ictx, i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
n = input_get(ictx, i, 0, 0);
|
n = input_get(ictx, i, 0, 0);
|
||||||
|
if (n == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (n == 38 || n == 48) {
|
if (n == 38 || n == 48) {
|
||||||
i++;
|
i++;
|
||||||
@@ -1789,7 +1915,6 @@ input_csi_dispatch_sgr(struct input_ctx *ictx)
|
|||||||
|
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 0:
|
case 0:
|
||||||
case 10:
|
|
||||||
memcpy(gc, &grid_default_cell, sizeof *gc);
|
memcpy(gc, &grid_default_cell, sizeof *gc);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
@@ -2043,48 +2168,30 @@ input_exit_rename(struct input_ctx *ictx)
|
|||||||
|
|
||||||
/* Open UTF-8 character. */
|
/* Open UTF-8 character. */
|
||||||
static int
|
static int
|
||||||
input_utf8_open(struct input_ctx *ictx)
|
input_top_bit_set(struct input_ctx *ictx)
|
||||||
{
|
{
|
||||||
struct utf8_data *ud = &ictx->utf8data;
|
struct utf8_data *ud = &ictx->utf8data;
|
||||||
|
|
||||||
if (utf8_open(ud, ictx->ch) != UTF8_MORE)
|
|
||||||
fatalx("UTF-8 open invalid %#x", ictx->ch);
|
|
||||||
|
|
||||||
log_debug("%s %hhu", __func__, ud->size);
|
|
||||||
ictx->last = -1;
|
ictx->last = -1;
|
||||||
|
|
||||||
return (0);
|
if (!ictx->utf8started) {
|
||||||
}
|
if (utf8_open(ud, ictx->ch) != UTF8_MORE)
|
||||||
|
return (0);
|
||||||
/* Append to UTF-8 character. */
|
ictx->utf8started = 1;
|
||||||
static int
|
|
||||||
input_utf8_add(struct input_ctx *ictx)
|
|
||||||
{
|
|
||||||
struct utf8_data *ud = &ictx->utf8data;
|
|
||||||
|
|
||||||
if (utf8_append(ud, ictx->ch) != UTF8_MORE)
|
|
||||||
fatalx("UTF-8 add invalid %#x", ictx->ch);
|
|
||||||
|
|
||||||
log_debug("%s", __func__);
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close UTF-8 string. */
|
|
||||||
static int
|
|
||||||
input_utf8_close(struct input_ctx *ictx)
|
|
||||||
{
|
|
||||||
struct utf8_data *ud = &ictx->utf8data;
|
|
||||||
|
|
||||||
if (utf8_append(ud, ictx->ch) != UTF8_DONE) {
|
|
||||||
/*
|
|
||||||
* An error here could be invalid UTF-8 or it could be a
|
|
||||||
* nonprintable character for which we can't get the
|
|
||||||
* width. Drop it.
|
|
||||||
*/
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (utf8_append(ud, ictx->ch)) {
|
||||||
|
case UTF8_MORE:
|
||||||
|
return (0);
|
||||||
|
case UTF8_ERROR:
|
||||||
|
ictx->utf8started = 0;
|
||||||
|
return (0);
|
||||||
|
case UTF8_DONE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ictx->utf8started = 0;
|
||||||
|
|
||||||
log_debug("%s %hhu '%*s' (width %hhu)", __func__, ud->size,
|
log_debug("%s %hhu '%*s' (width %hhu)", __func__, ud->size,
|
||||||
(int)ud->size, ud->data, ud->width);
|
(int)ud->size, ud->data, ud->width);
|
||||||
|
|
||||||
@@ -2128,7 +2235,7 @@ bad:
|
|||||||
free(copy);
|
free(copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle the OSC 10 sequence for setting background colour. */
|
/* Handle the OSC 10 sequence for setting foreground colour. */
|
||||||
static void
|
static void
|
||||||
input_osc_10(struct window_pane *wp, const char *p)
|
input_osc_10(struct window_pane *wp, const char *p)
|
||||||
{
|
{
|
||||||
|
|||||||
3
job.c
3
job.c
@@ -43,7 +43,7 @@ struct joblist all_jobs = LIST_HEAD_INITIALIZER(all_jobs);
|
|||||||
struct job *
|
struct job *
|
||||||
job_run(const char *cmd, struct session *s, const char *cwd,
|
job_run(const char *cmd, struct session *s, const char *cwd,
|
||||||
job_update_cb updatecb, job_complete_cb completecb, job_free_cb freecb,
|
job_update_cb updatecb, job_complete_cb completecb, job_free_cb freecb,
|
||||||
void *data)
|
void *data, int flags)
|
||||||
{
|
{
|
||||||
struct job *job;
|
struct job *job;
|
||||||
struct environ *env;
|
struct environ *env;
|
||||||
@@ -110,6 +110,7 @@ job_run(const char *cmd, struct session *s, const char *cwd,
|
|||||||
|
|
||||||
job = xmalloc(sizeof *job);
|
job = xmalloc(sizeof *job);
|
||||||
job->state = JOB_RUNNING;
|
job->state = JOB_RUNNING;
|
||||||
|
job->flags = flags;
|
||||||
|
|
||||||
job->cmd = xstrdup(cmd);
|
job->cmd = xstrdup(cmd);
|
||||||
job->pid = pid;
|
job->pid = pid;
|
||||||
|
|||||||
@@ -24,17 +24,19 @@
|
|||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
RB_GENERATE(key_bindings, key_binding, entry, key_bindings_cmp);
|
static int key_bindings_cmp(struct key_binding *, struct key_binding *);
|
||||||
RB_GENERATE(key_tables, key_table, entry, key_table_cmp);
|
RB_GENERATE_STATIC(key_bindings, key_binding, entry, key_bindings_cmp);
|
||||||
struct key_tables key_tables = RB_INITIALIZER(&key_tables);
|
static int key_table_cmp(struct key_table *, struct key_table *);
|
||||||
|
RB_GENERATE_STATIC(key_tables, key_table, entry, key_table_cmp);
|
||||||
|
static struct key_tables key_tables = RB_INITIALIZER(&key_tables);
|
||||||
|
|
||||||
int
|
static int
|
||||||
key_table_cmp(struct key_table *e1, struct key_table *e2)
|
key_table_cmp(struct key_table *table1, struct key_table *table2)
|
||||||
{
|
{
|
||||||
return (strcmp(e1->name, e2->name));
|
return (strcmp(table1->name, table2->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
key_bindings_cmp(struct key_binding *bd1, struct key_binding *bd2)
|
key_bindings_cmp(struct key_binding *bd1, struct key_binding *bd2)
|
||||||
{
|
{
|
||||||
if (bd1->key < bd2->key)
|
if (bd1->key < bd2->key)
|
||||||
@@ -64,6 +66,18 @@ key_bindings_get_table(const char *name, int create)
|
|||||||
return (table);
|
return (table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct key_table *
|
||||||
|
key_bindings_first_table(void)
|
||||||
|
{
|
||||||
|
return (RB_MIN(key_tables, &key_tables));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct key_table *
|
||||||
|
key_bindings_next_table(struct key_table *table)
|
||||||
|
{
|
||||||
|
return (RB_NEXT(key_tables, &key_tables, table));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
key_bindings_unref_table(struct key_table *table)
|
key_bindings_unref_table(struct key_table *table)
|
||||||
{
|
{
|
||||||
@@ -83,6 +97,27 @@ key_bindings_unref_table(struct key_table *table)
|
|||||||
free(table);
|
free(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct key_binding *
|
||||||
|
key_bindings_get(struct key_table *table, key_code key)
|
||||||
|
{
|
||||||
|
struct key_binding bd;
|
||||||
|
|
||||||
|
bd.key = key;
|
||||||
|
return (RB_FIND(key_bindings, &table->key_bindings, &bd));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct key_binding *
|
||||||
|
key_bindings_first(struct key_table *table)
|
||||||
|
{
|
||||||
|
return (RB_MIN(key_bindings, &table->key_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct key_binding *
|
||||||
|
key_bindings_next(__unused struct key_table *table, struct key_binding *bd)
|
||||||
|
{
|
||||||
|
return (RB_NEXT(key_bindings, &table->key_bindings, bd));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
key_bindings_add(const char *name, key_code key, int repeat,
|
key_bindings_add(const char *name, key_code key, int repeat,
|
||||||
struct cmd_list *cmdlist)
|
struct cmd_list *cmdlist)
|
||||||
@@ -162,13 +197,13 @@ key_bindings_init(void)
|
|||||||
"bind ! break-pane",
|
"bind ! break-pane",
|
||||||
"bind '\"' split-window",
|
"bind '\"' split-window",
|
||||||
"bind '#' list-buffers",
|
"bind '#' list-buffers",
|
||||||
"bind '$' command-prompt -I'#S' \"rename-session '%%'\"",
|
"bind '$' command-prompt -I'#S' \"rename-session -- '%%'\"",
|
||||||
"bind % split-window -h",
|
"bind % split-window -h",
|
||||||
"bind & confirm-before -p\"kill-window #W? (y/n)\" kill-window",
|
"bind & confirm-before -p\"kill-window #W? (y/n)\" kill-window",
|
||||||
"bind \"'\" command-prompt -pindex \"select-window -t ':%%'\"",
|
"bind \"'\" command-prompt -pindex \"select-window -t ':%%'\"",
|
||||||
"bind ( switch-client -p",
|
"bind ( switch-client -p",
|
||||||
"bind ) switch-client -n",
|
"bind ) switch-client -n",
|
||||||
"bind , command-prompt -I'#W' \"rename-window '%%'\"",
|
"bind , command-prompt -I'#W' \"rename-window -- '%%'\"",
|
||||||
"bind - delete-buffer",
|
"bind - delete-buffer",
|
||||||
"bind . command-prompt \"move-window -t '%%'\"",
|
"bind . command-prompt \"move-window -t '%%'\"",
|
||||||
"bind 0 select-window -t:=0",
|
"bind 0 select-window -t:=0",
|
||||||
@@ -183,16 +218,17 @@ key_bindings_init(void)
|
|||||||
"bind 9 select-window -t:=9",
|
"bind 9 select-window -t:=9",
|
||||||
"bind : command-prompt",
|
"bind : command-prompt",
|
||||||
"bind \\; last-pane",
|
"bind \\; last-pane",
|
||||||
"bind = choose-buffer",
|
"bind = choose-buffer -Z",
|
||||||
"bind ? list-keys",
|
"bind ? list-keys",
|
||||||
"bind D choose-client",
|
"bind D choose-client -Z",
|
||||||
|
"bind E select-layout -E",
|
||||||
"bind L switch-client -l",
|
"bind L switch-client -l",
|
||||||
"bind M select-pane -M",
|
"bind M select-pane -M",
|
||||||
"bind [ copy-mode",
|
"bind [ copy-mode",
|
||||||
"bind ] paste-buffer",
|
"bind ] paste-buffer",
|
||||||
"bind c new-window",
|
"bind c new-window",
|
||||||
"bind d detach-client",
|
"bind d detach-client",
|
||||||
"bind f command-prompt \"find-window '%%'\"",
|
"bind f command-prompt \"find-window -- '%%'\"",
|
||||||
"bind i display-message",
|
"bind i display-message",
|
||||||
"bind l last-window",
|
"bind l last-window",
|
||||||
"bind m select-pane -m",
|
"bind m select-pane -m",
|
||||||
@@ -201,9 +237,9 @@ key_bindings_init(void)
|
|||||||
"bind p previous-window",
|
"bind p previous-window",
|
||||||
"bind q display-panes",
|
"bind q display-panes",
|
||||||
"bind r refresh-client",
|
"bind r refresh-client",
|
||||||
"bind s choose-tree -s",
|
"bind s choose-tree -Zs",
|
||||||
"bind t clock-mode",
|
"bind t clock-mode",
|
||||||
"bind w choose-tree -w",
|
"bind w choose-tree -Zw",
|
||||||
"bind x confirm-before -p\"kill-pane #P? (y/n)\" kill-pane",
|
"bind x confirm-before -p\"kill-pane #P? (y/n)\" kill-pane",
|
||||||
"bind z resize-pane -Z",
|
"bind z resize-pane -Z",
|
||||||
"bind { swap-pane -U",
|
"bind { swap-pane -U",
|
||||||
|
|||||||
@@ -166,9 +166,11 @@ key_string_lookup_string(const char *string)
|
|||||||
enum utf8_state more;
|
enum utf8_state more;
|
||||||
wchar_t wc;
|
wchar_t wc;
|
||||||
|
|
||||||
/* Is this no key? */
|
/* Is this no key or any key? */
|
||||||
if (strcasecmp(string, "None") == 0)
|
if (strcasecmp(string, "None") == 0)
|
||||||
return (KEYC_NONE);
|
return (KEYC_NONE);
|
||||||
|
if (strcasecmp(string, "Any") == 0)
|
||||||
|
return (KEYC_ANY);
|
||||||
|
|
||||||
/* Is this a hexadecimal value? */
|
/* Is this a hexadecimal value? */
|
||||||
if (string[0] == '0' && string[1] == 'x') {
|
if (string[0] == '0' && string[1] == 'x') {
|
||||||
@@ -251,6 +253,8 @@ key_string_lookup_key(key_code key)
|
|||||||
/* Handle special keys. */
|
/* Handle special keys. */
|
||||||
if (key == KEYC_UNKNOWN)
|
if (key == KEYC_UNKNOWN)
|
||||||
return ("Unknown");
|
return ("Unknown");
|
||||||
|
if (key == KEYC_ANY)
|
||||||
|
return ("Any");
|
||||||
if (key == KEYC_FOCUS_IN)
|
if (key == KEYC_FOCUS_IN)
|
||||||
return ("FocusIn");
|
return ("FocusIn");
|
||||||
if (key == KEYC_FOCUS_OUT)
|
if (key == KEYC_FOCUS_OUT)
|
||||||
|
|||||||
84
layout-set.c
84
layout-set.c
@@ -115,11 +115,11 @@ layout_set_previous(struct window *w)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
layout_set_even_h(struct window *w)
|
layout_set_even(struct window *w, enum layout_type type)
|
||||||
{
|
{
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct layout_cell *lc, *lcnew;
|
struct layout_cell *lc, *lcnew;
|
||||||
u_int i, n, width, xoff;
|
u_int n;
|
||||||
|
|
||||||
layout_print_cell(w->layout_root, __func__, 1);
|
layout_print_cell(w->layout_root, __func__, 1);
|
||||||
|
|
||||||
@@ -128,36 +128,23 @@ layout_set_even_h(struct window *w)
|
|||||||
if (n <= 1)
|
if (n <= 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* How many can we fit? */
|
|
||||||
width = (w->sx - (n - 1)) / n;
|
|
||||||
if (width < PANE_MINIMUM)
|
|
||||||
width = PANE_MINIMUM;
|
|
||||||
|
|
||||||
/* Free the old root and construct a new. */
|
/* Free the old root and construct a new. */
|
||||||
layout_free(w);
|
layout_free(w);
|
||||||
lc = w->layout_root = layout_create_cell(NULL);
|
lc = w->layout_root = layout_create_cell(NULL);
|
||||||
layout_set_size(lc, w->sx, w->sy, 0, 0);
|
layout_set_size(lc, w->sx, w->sy, 0, 0);
|
||||||
layout_make_node(lc, LAYOUT_LEFTRIGHT);
|
layout_make_node(lc, type);
|
||||||
|
|
||||||
/* Build new leaf cells. */
|
/* Build new leaf cells. */
|
||||||
i = xoff = 0;
|
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
/* Create child cell. */
|
|
||||||
lcnew = layout_create_cell(lc);
|
lcnew = layout_create_cell(lc);
|
||||||
layout_set_size(lcnew, width, w->sy, xoff, 0);
|
|
||||||
layout_make_leaf(lcnew, wp);
|
layout_make_leaf(lcnew, wp);
|
||||||
|
lcnew->sx = w->sx;
|
||||||
|
lcnew->sy = w->sy;
|
||||||
TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry);
|
TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry);
|
||||||
|
|
||||||
i++;
|
|
||||||
xoff += width + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate any remaining space. */
|
/* Spread out cells. */
|
||||||
if (w->sx > xoff - 1) {
|
layout_spread_cell(w, lc);
|
||||||
lc = TAILQ_LAST(&lc->cells, layout_cells);
|
|
||||||
layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT,
|
|
||||||
w->sx - (xoff - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fix cell offsets. */
|
/* Fix cell offsets. */
|
||||||
layout_fix_offsets(lc);
|
layout_fix_offsets(lc);
|
||||||
@@ -169,59 +156,16 @@ layout_set_even_h(struct window *w)
|
|||||||
server_redraw_window(w);
|
server_redraw_window(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
layout_set_even_h(struct window *w)
|
||||||
|
{
|
||||||
|
layout_set_even(w, LAYOUT_LEFTRIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
layout_set_even_v(struct window *w)
|
layout_set_even_v(struct window *w)
|
||||||
{
|
{
|
||||||
struct window_pane *wp;
|
layout_set_even(w, LAYOUT_TOPBOTTOM);
|
||||||
struct layout_cell *lc, *lcnew;
|
|
||||||
u_int i, n, height, yoff;
|
|
||||||
|
|
||||||
layout_print_cell(w->layout_root, __func__, 1);
|
|
||||||
|
|
||||||
/* Get number of panes. */
|
|
||||||
n = window_count_panes(w);
|
|
||||||
if (n <= 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* How many can we fit? */
|
|
||||||
height = (w->sy - (n - 1)) / n;
|
|
||||||
if (height < PANE_MINIMUM)
|
|
||||||
height = PANE_MINIMUM;
|
|
||||||
|
|
||||||
/* Free the old root and construct a new. */
|
|
||||||
layout_free(w);
|
|
||||||
lc = w->layout_root = layout_create_cell(NULL);
|
|
||||||
layout_set_size(lc, w->sx, w->sy, 0, 0);
|
|
||||||
layout_make_node(lc, LAYOUT_TOPBOTTOM);
|
|
||||||
|
|
||||||
/* Build new leaf cells. */
|
|
||||||
i = yoff = 0;
|
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
||||||
/* Create child cell. */
|
|
||||||
lcnew = layout_create_cell(lc);
|
|
||||||
layout_set_size(lcnew, w->sx, height, 0, yoff);
|
|
||||||
layout_make_leaf(lcnew, wp);
|
|
||||||
TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry);
|
|
||||||
|
|
||||||
i++;
|
|
||||||
yoff += height + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate any remaining space. */
|
|
||||||
if (w->sy > yoff - 1) {
|
|
||||||
lc = TAILQ_LAST(&lc->cells, layout_cells);
|
|
||||||
layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM,
|
|
||||||
w->sy - (yoff - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fix cell offsets. */
|
|
||||||
layout_fix_offsets(lc);
|
|
||||||
layout_fix_panes(w, w->sx, w->sy);
|
|
||||||
|
|
||||||
layout_print_cell(w->layout_root, __func__, 1);
|
|
||||||
|
|
||||||
notify_window("window-layout-changed", w);
|
|
||||||
server_redraw_window(w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
168
layout.c
168
layout.c
@@ -97,9 +97,24 @@ void
|
|||||||
layout_print_cell(struct layout_cell *lc, const char *hdr, u_int n)
|
layout_print_cell(struct layout_cell *lc, const char *hdr, u_int n)
|
||||||
{
|
{
|
||||||
struct layout_cell *lcchild;
|
struct layout_cell *lcchild;
|
||||||
|
const char *type;
|
||||||
|
|
||||||
log_debug("%s:%*s%p type %u [parent %p] wp=%p [%u,%u %ux%u]", hdr, n,
|
switch (lc->type) {
|
||||||
" ", lc, lc->type, lc->parent, lc->wp, lc->xoff, lc->yoff, lc->sx,
|
case LAYOUT_LEFTRIGHT:
|
||||||
|
type = "LEFTRIGHT";
|
||||||
|
break;
|
||||||
|
case LAYOUT_TOPBOTTOM:
|
||||||
|
type = "TOPBOTTOM";
|
||||||
|
break;
|
||||||
|
case LAYOUT_WINDOWPANE:
|
||||||
|
type = "WINDOWPANE";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
type = "UNKNOWN";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
log_debug("%s:%*s%p type %s [parent %p] wp=%p [%u,%u %ux%u]", hdr, n,
|
||||||
|
" ", lc, type, lc->parent, lc->wp, lc->xoff, lc->yoff, lc->sx,
|
||||||
lc->sy);
|
lc->sy);
|
||||||
switch (lc->type) {
|
switch (lc->type) {
|
||||||
case LAYOUT_LEFTRIGHT:
|
case LAYOUT_LEFTRIGHT:
|
||||||
@@ -112,6 +127,42 @@ layout_print_cell(struct layout_cell *lc, const char *hdr, u_int n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct layout_cell *
|
||||||
|
layout_search_by_border(struct layout_cell *lc, u_int x, u_int y)
|
||||||
|
{
|
||||||
|
struct layout_cell *lcchild, *last = NULL;
|
||||||
|
|
||||||
|
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
||||||
|
if (x >= lcchild->xoff && x < lcchild->xoff + lcchild->sx &&
|
||||||
|
y >= lcchild->yoff && y < lcchild->yoff + lcchild->sy) {
|
||||||
|
/* Inside the cell - recurse. */
|
||||||
|
return (layout_search_by_border(lcchild, x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last == NULL) {
|
||||||
|
last = lcchild;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (lc->type) {
|
||||||
|
case LAYOUT_LEFTRIGHT:
|
||||||
|
if (x < lcchild->xoff && x >= last->xoff + last->sx)
|
||||||
|
return (last);
|
||||||
|
break;
|
||||||
|
case LAYOUT_TOPBOTTOM:
|
||||||
|
if (y < lcchild->yoff && y >= last->yoff + last->sy)
|
||||||
|
return (last);
|
||||||
|
break;
|
||||||
|
case LAYOUT_WINDOWPANE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
last = lcchild;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, u_int xoff,
|
layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, u_int xoff,
|
||||||
u_int yoff)
|
u_int yoff)
|
||||||
@@ -535,29 +586,11 @@ layout_resize_pane_to(struct window_pane *wp, enum layout_type type,
|
|||||||
layout_resize_pane(wp, type, change, 1);
|
layout_resize_pane(wp, type, change, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resize a single pane within the layout. */
|
|
||||||
void
|
void
|
||||||
layout_resize_pane(struct window_pane *wp, enum layout_type type, int change,
|
layout_resize_layout(struct window *w, struct layout_cell *lc,
|
||||||
int opposite)
|
enum layout_type type, int change, int opposite)
|
||||||
{
|
{
|
||||||
struct window *w = wp->window;
|
int needed, size;
|
||||||
struct layout_cell *lc, *lcparent;
|
|
||||||
int needed, size;
|
|
||||||
|
|
||||||
lc = wp->layout_cell;
|
|
||||||
|
|
||||||
/* Find next parent of the same type. */
|
|
||||||
lcparent = lc->parent;
|
|
||||||
while (lcparent != NULL && lcparent->type != type) {
|
|
||||||
lc = lcparent;
|
|
||||||
lcparent = lc->parent;
|
|
||||||
}
|
|
||||||
if (lcparent == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* If this is the last cell, move back one. */
|
|
||||||
if (lc == TAILQ_LAST(&lcparent->cells, layout_cells))
|
|
||||||
lc = TAILQ_PREV(lc, layout_cells, entry);
|
|
||||||
|
|
||||||
/* Grow or shrink the cell. */
|
/* Grow or shrink the cell. */
|
||||||
needed = change;
|
needed = change;
|
||||||
@@ -576,9 +609,34 @@ layout_resize_pane(struct window_pane *wp, enum layout_type type, int change,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fix cell offsets. */
|
/* Fix cell offsets. */
|
||||||
layout_fix_offsets(wp->window->layout_root);
|
layout_fix_offsets(w->layout_root);
|
||||||
layout_fix_panes(wp->window, wp->window->sx, wp->window->sy);
|
layout_fix_panes(w, w->sx, w->sy);
|
||||||
notify_window("window-layout-changed", wp->window);
|
notify_window("window-layout-changed", w);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Resize a single pane within the layout. */
|
||||||
|
void
|
||||||
|
layout_resize_pane(struct window_pane *wp, enum layout_type type, int change,
|
||||||
|
int opposite)
|
||||||
|
{
|
||||||
|
struct layout_cell *lc, *lcparent;
|
||||||
|
|
||||||
|
lc = wp->layout_cell;
|
||||||
|
|
||||||
|
/* Find next parent of the same type. */
|
||||||
|
lcparent = lc->parent;
|
||||||
|
while (lcparent != NULL && lcparent->type != type) {
|
||||||
|
lc = lcparent;
|
||||||
|
lcparent = lc->parent;
|
||||||
|
}
|
||||||
|
if (lcparent == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* If this is the last cell, move back one. */
|
||||||
|
if (lc == TAILQ_LAST(&lcparent->cells, layout_cells))
|
||||||
|
lc = TAILQ_PREV(lc, layout_cells, entry);
|
||||||
|
|
||||||
|
layout_resize_layout(wp->window, lc, type, change, opposite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function to grow pane. */
|
/* Helper function to grow pane. */
|
||||||
@@ -983,3 +1041,61 @@ layout_close_pane(struct window_pane *wp)
|
|||||||
}
|
}
|
||||||
notify_window("window-layout-changed", w);
|
notify_window("window-layout-changed", w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
layout_spread_cell(struct window *w, struct layout_cell *parent)
|
||||||
|
{
|
||||||
|
struct layout_cell *lc;
|
||||||
|
u_int number, each, size;
|
||||||
|
int change, changed;
|
||||||
|
|
||||||
|
number = 0;
|
||||||
|
TAILQ_FOREACH (lc, &parent->cells, entry)
|
||||||
|
number++;
|
||||||
|
if (number <= 1)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (parent->type == LAYOUT_LEFTRIGHT)
|
||||||
|
size = parent->sx;
|
||||||
|
else if (parent->type == LAYOUT_TOPBOTTOM)
|
||||||
|
size = parent->sy;
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
each = (size - (number - 1)) / number;
|
||||||
|
|
||||||
|
changed = 0;
|
||||||
|
TAILQ_FOREACH (lc, &parent->cells, entry) {
|
||||||
|
if (TAILQ_NEXT(lc, entry) == NULL)
|
||||||
|
each = size - ((each + 1) * (number - 1));
|
||||||
|
change = 0;
|
||||||
|
if (parent->type == LAYOUT_LEFTRIGHT) {
|
||||||
|
change = each - (int)lc->sx;
|
||||||
|
layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT, change);
|
||||||
|
} else if (parent->type == LAYOUT_TOPBOTTOM) {
|
||||||
|
change = each - (int)lc->sy;
|
||||||
|
layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM, change);
|
||||||
|
}
|
||||||
|
if (change != 0)
|
||||||
|
changed = 1;
|
||||||
|
}
|
||||||
|
return (changed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
layout_spread_out(struct window_pane *wp)
|
||||||
|
{
|
||||||
|
struct layout_cell *parent;
|
||||||
|
struct window *w = wp->window;
|
||||||
|
|
||||||
|
parent = wp->layout_cell->parent;
|
||||||
|
if (parent == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (layout_spread_cell(w, parent)) {
|
||||||
|
layout_fix_offsets(parent);
|
||||||
|
layout_fix_panes(w, w->sx, w->sy);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while ((parent = parent->parent) != NULL);
|
||||||
|
}
|
||||||
|
|||||||
161
mode-tree.c
161
mode-tree.c
@@ -31,6 +31,7 @@ TAILQ_HEAD(mode_tree_list, mode_tree_item);
|
|||||||
struct mode_tree_data {
|
struct mode_tree_data {
|
||||||
int dead;
|
int dead;
|
||||||
u_int references;
|
u_int references;
|
||||||
|
int zoomed;
|
||||||
|
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
void *modedata;
|
void *modedata;
|
||||||
@@ -39,10 +40,9 @@ struct mode_tree_data {
|
|||||||
u_int sort_size;
|
u_int sort_size;
|
||||||
u_int sort_type;
|
u_int sort_type;
|
||||||
|
|
||||||
void (*buildcb)(void *, u_int, uint64_t *,
|
mode_tree_build_cb buildcb;
|
||||||
const char *);
|
mode_tree_draw_cb drawcb;
|
||||||
struct screen *(*drawcb)(void *, void *, u_int, u_int);
|
mode_tree_search_cb searchcb;
|
||||||
int (*searchcb)(void*, void *, const char *);
|
|
||||||
|
|
||||||
struct mode_tree_list children;
|
struct mode_tree_list children;
|
||||||
struct mode_tree_list saved;
|
struct mode_tree_list saved;
|
||||||
@@ -63,6 +63,7 @@ struct mode_tree_data {
|
|||||||
int preview;
|
int preview;
|
||||||
char *search;
|
char *search;
|
||||||
char *filter;
|
char *filter;
|
||||||
|
int no_matches;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mode_tree_item {
|
struct mode_tree_item {
|
||||||
@@ -192,27 +193,6 @@ mode_tree_clear_tagged(struct mode_tree_list *mtl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
|
|
||||||
{
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
for (i = 0; i < mtd->line_size; i++) {
|
|
||||||
if (mtd->line_list[i].item->tag == tag)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i != mtd->line_size) {
|
|
||||||
mtd->current = i;
|
|
||||||
if (mtd->current > mtd->height - 1)
|
|
||||||
mtd->offset = mtd->current - mtd->height + 1;
|
|
||||||
else
|
|
||||||
mtd->offset = 0;
|
|
||||||
} else {
|
|
||||||
mtd->current = 0;
|
|
||||||
mtd->offset = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
mode_tree_up(struct mode_tree_data *mtd, int wrap)
|
mode_tree_up(struct mode_tree_data *mtd, int wrap)
|
||||||
{
|
{
|
||||||
if (mtd->current == 0) {
|
if (mtd->current == 0) {
|
||||||
@@ -249,6 +229,36 @@ mode_tree_get_current(struct mode_tree_data *mtd)
|
|||||||
return (mtd->line_list[mtd->current].item->itemdata);
|
return (mtd->line_list[mtd->current].item->itemdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mode_tree_expand_current(struct mode_tree_data *mtd)
|
||||||
|
{
|
||||||
|
if (!mtd->line_list[mtd->current].item->expanded) {
|
||||||
|
mtd->line_list[mtd->current].item->expanded = 1;
|
||||||
|
mode_tree_build(mtd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
|
||||||
|
{
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
for (i = 0; i < mtd->line_size; i++) {
|
||||||
|
if (mtd->line_list[i].item->tag == tag)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i != mtd->line_size) {
|
||||||
|
mtd->current = i;
|
||||||
|
if (mtd->current > mtd->height - 1)
|
||||||
|
mtd->offset = mtd->current - mtd->height + 1;
|
||||||
|
else
|
||||||
|
mtd->offset = 0;
|
||||||
|
} else {
|
||||||
|
mtd->current = 0;
|
||||||
|
mtd->offset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
u_int
|
u_int
|
||||||
mode_tree_count_tagged(struct mode_tree_data *mtd)
|
mode_tree_count_tagged(struct mode_tree_data *mtd)
|
||||||
{
|
{
|
||||||
@@ -265,8 +275,8 @@ mode_tree_count_tagged(struct mode_tree_data *mtd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mode_tree_each_tagged(struct mode_tree_data *mtd, void (*cb)(void *, void *,
|
mode_tree_each_tagged(struct mode_tree_data *mtd, mode_tree_each_cb cb,
|
||||||
key_code), key_code key, int current)
|
struct client *c, key_code key, int current)
|
||||||
{
|
{
|
||||||
struct mode_tree_item *mti;
|
struct mode_tree_item *mti;
|
||||||
u_int i;
|
u_int i;
|
||||||
@@ -277,21 +287,20 @@ mode_tree_each_tagged(struct mode_tree_data *mtd, void (*cb)(void *, void *,
|
|||||||
mti = mtd->line_list[i].item;
|
mti = mtd->line_list[i].item;
|
||||||
if (mti->tagged) {
|
if (mti->tagged) {
|
||||||
fired = 1;
|
fired = 1;
|
||||||
cb(mtd->modedata, mti->itemdata, key);
|
cb(mtd->modedata, mti->itemdata, c, key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!fired && current) {
|
if (!fired && current) {
|
||||||
mti = mtd->line_list[mtd->current].item;
|
mti = mtd->line_list[mtd->current].item;
|
||||||
cb(mtd->modedata, mti->itemdata, key);
|
cb(mtd->modedata, mti->itemdata, c, key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mode_tree_data *
|
struct mode_tree_data *
|
||||||
mode_tree_start(struct window_pane *wp, struct args *args,
|
mode_tree_start(struct window_pane *wp, struct args *args,
|
||||||
void (*buildcb)(void *, u_int, uint64_t *, const char *),
|
mode_tree_build_cb buildcb, mode_tree_draw_cb drawcb,
|
||||||
struct screen *(*drawcb)(void *, void *, u_int, u_int),
|
mode_tree_search_cb searchcb, void *modedata, const char **sort_list,
|
||||||
int (*searchcb)(void *, void *, const char *), void *modedata,
|
u_int sort_size, struct screen **s)
|
||||||
const char **sort_list, u_int sort_size, struct screen **s)
|
|
||||||
{
|
{
|
||||||
struct mode_tree_data *mtd;
|
struct mode_tree_data *mtd;
|
||||||
const char *sort;
|
const char *sort;
|
||||||
@@ -335,6 +344,19 @@ mode_tree_start(struct window_pane *wp, struct args *args,
|
|||||||
return (mtd);
|
return (mtd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mode_tree_zoom(struct mode_tree_data *mtd, struct args *args)
|
||||||
|
{
|
||||||
|
struct window_pane *wp = mtd->wp;
|
||||||
|
|
||||||
|
if (args_has(args, 'Z')) {
|
||||||
|
mtd->zoomed = (wp->window->flags & WINDOW_ZOOMED);
|
||||||
|
if (!mtd->zoomed && window_zoom(wp) == 0)
|
||||||
|
server_redraw_window(wp->window);
|
||||||
|
} else
|
||||||
|
mtd->zoomed = -1;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mode_tree_build(struct mode_tree_data *mtd)
|
mode_tree_build(struct mode_tree_data *mtd)
|
||||||
{
|
{
|
||||||
@@ -350,7 +372,8 @@ mode_tree_build(struct mode_tree_data *mtd)
|
|||||||
TAILQ_INIT(&mtd->children);
|
TAILQ_INIT(&mtd->children);
|
||||||
|
|
||||||
mtd->buildcb(mtd->modedata, mtd->sort_type, &tag, mtd->filter);
|
mtd->buildcb(mtd->modedata, mtd->sort_type, &tag, mtd->filter);
|
||||||
if (TAILQ_EMPTY(&mtd->children))
|
mtd->no_matches = TAILQ_EMPTY(&mtd->children);
|
||||||
|
if (mtd->no_matches)
|
||||||
mtd->buildcb(mtd->modedata, mtd->sort_type, &tag, NULL);
|
mtd->buildcb(mtd->modedata, mtd->sort_type, &tag, NULL);
|
||||||
|
|
||||||
mode_tree_free_items(&mtd->saved);
|
mode_tree_free_items(&mtd->saved);
|
||||||
@@ -385,6 +408,11 @@ mode_tree_remove_ref(struct mode_tree_data *mtd)
|
|||||||
void
|
void
|
||||||
mode_tree_free(struct mode_tree_data *mtd)
|
mode_tree_free(struct mode_tree_data *mtd)
|
||||||
{
|
{
|
||||||
|
struct window_pane *wp = mtd->wp;
|
||||||
|
|
||||||
|
if (mtd->zoomed == 0)
|
||||||
|
server_unzoom_window(wp->window);
|
||||||
|
|
||||||
mode_tree_free_items(&mtd->children);
|
mode_tree_free_items(&mtd->children);
|
||||||
mode_tree_clear_lines(mtd);
|
mode_tree_clear_lines(mtd);
|
||||||
screen_free(&mtd->screen);
|
screen_free(&mtd->screen);
|
||||||
@@ -463,7 +491,7 @@ void
|
|||||||
mode_tree_draw(struct mode_tree_data *mtd)
|
mode_tree_draw(struct mode_tree_data *mtd)
|
||||||
{
|
{
|
||||||
struct window_pane *wp = mtd->wp;
|
struct window_pane *wp = mtd->wp;
|
||||||
struct screen *s = &mtd->screen, *box = NULL;
|
struct screen *s = &mtd->screen;
|
||||||
struct mode_tree_line *line;
|
struct mode_tree_line *line;
|
||||||
struct mode_tree_item *mti;
|
struct mode_tree_item *mti;
|
||||||
struct options *oo = wp->window->options;
|
struct options *oo = wp->window->options;
|
||||||
@@ -472,7 +500,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
|
|||||||
u_int w, h, i, j, sy, box_x, box_y;
|
u_int w, h, i, j, sy, box_x, box_y;
|
||||||
char *text, *start, key[7];
|
char *text, *start, key[7];
|
||||||
const char *tag, *symbol;
|
const char *tag, *symbol;
|
||||||
size_t size;
|
size_t size, n;
|
||||||
int keylen;
|
int keylen;
|
||||||
|
|
||||||
if (mtd->line_size == 0)
|
if (mtd->line_size == 0)
|
||||||
@@ -554,10 +582,12 @@ mode_tree_draw(struct mode_tree_data *mtd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i != mtd->current) {
|
if (i != mtd->current) {
|
||||||
screen_write_puts(&ctx, &gc0, "%.*s", w, text);
|
screen_write_nputs(&ctx, w, &gc0, "%s", text);
|
||||||
screen_write_clearendofline(&ctx, 8);
|
screen_write_clearendofline(&ctx, 8);
|
||||||
} else
|
} else {
|
||||||
screen_write_puts(&ctx, &gc, "%-*.*s", w, w, text);
|
screen_write_nputs(&ctx, w, &gc, "%s", text);
|
||||||
|
screen_write_clearendofline(&ctx, gc.bg);
|
||||||
|
}
|
||||||
free(text);
|
free(text);
|
||||||
|
|
||||||
if (mti->tagged) {
|
if (mti->tagged) {
|
||||||
@@ -578,24 +608,33 @@ mode_tree_draw(struct mode_tree_data *mtd)
|
|||||||
screen_write_cursormove(&ctx, 0, h);
|
screen_write_cursormove(&ctx, 0, h);
|
||||||
screen_write_box(&ctx, w, sy - h);
|
screen_write_box(&ctx, w, sy - h);
|
||||||
|
|
||||||
xasprintf(&text, " %s (sort: %s) ", mti->name,
|
xasprintf(&text, " %s (sort: %s)", mti->name,
|
||||||
mtd->sort_list[mtd->sort_type]);
|
mtd->sort_list[mtd->sort_type]);
|
||||||
if (w - 2 >= strlen(text)) {
|
if (w - 2 >= strlen(text)) {
|
||||||
screen_write_cursormove(&ctx, 1, h);
|
screen_write_cursormove(&ctx, 1, h);
|
||||||
screen_write_puts(&ctx, &gc0, "%s", text);
|
screen_write_puts(&ctx, &gc0, "%s", text);
|
||||||
|
|
||||||
|
if (mtd->no_matches)
|
||||||
|
n = (sizeof "no matches") - 1;
|
||||||
|
else
|
||||||
|
n = (sizeof "active") - 1;
|
||||||
|
if (mtd->filter != NULL && w - 2 >= strlen(text) + 10 + n + 2) {
|
||||||
|
screen_write_puts(&ctx, &gc0, " (filter: ");
|
||||||
|
if (mtd->no_matches)
|
||||||
|
screen_write_puts(&ctx, &gc, "no matches");
|
||||||
|
else
|
||||||
|
screen_write_puts(&ctx, &gc0, "active");
|
||||||
|
screen_write_puts(&ctx, &gc0, ") ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(text);
|
free(text);
|
||||||
|
|
||||||
box_x = w - 4;
|
box_x = w - 4;
|
||||||
box_y = sy - h - 2;
|
box_y = sy - h - 2;
|
||||||
|
|
||||||
if (box_x != 0 && box_y != 0)
|
if (box_x != 0 && box_y != 0) {
|
||||||
box = mtd->drawcb(mtd->modedata, mti->itemdata, box_x, box_y);
|
|
||||||
if (box != NULL) {
|
|
||||||
screen_write_cursormove(&ctx, 2, h + 1);
|
screen_write_cursormove(&ctx, 2, h + 1);
|
||||||
screen_write_copy(&ctx, box, 0, 0, box_x, box_y, NULL, NULL);
|
mtd->drawcb(mtd->modedata, mti->itemdata, &ctx, box_x, box_y);
|
||||||
|
|
||||||
screen_free(box);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_write_stop(&ctx);
|
screen_write_stop(&ctx);
|
||||||
@@ -722,7 +761,7 @@ mode_tree_filter_free(void *data)
|
|||||||
|
|
||||||
int
|
int
|
||||||
mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
|
mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
|
||||||
struct mouse_event *m)
|
struct mouse_event *m, u_int *xp, u_int *yp)
|
||||||
{
|
{
|
||||||
struct mode_tree_line *line;
|
struct mode_tree_line *line;
|
||||||
struct mode_tree_item *current, *parent;
|
struct mode_tree_item *current, *parent;
|
||||||
@@ -730,20 +769,31 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
|
|||||||
int choice;
|
int choice;
|
||||||
key_code tmp;
|
key_code tmp;
|
||||||
|
|
||||||
if (*key == KEYC_MOUSEDOWN1_PANE) {
|
if (KEYC_IS_MOUSE(*key)) {
|
||||||
if (cmd_mouse_at(mtd->wp, m, &x, &y, 0) != 0) {
|
if (cmd_mouse_at(mtd->wp, m, &x, &y, 0) != 0) {
|
||||||
*key = KEYC_NONE;
|
*key = KEYC_NONE;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
if (xp != NULL)
|
||||||
|
*xp = x;
|
||||||
|
if (yp != NULL)
|
||||||
|
*yp = y;
|
||||||
if (x > mtd->width || y > mtd->height) {
|
if (x > mtd->width || y > mtd->height) {
|
||||||
*key = KEYC_NONE;
|
if (!mtd->preview)
|
||||||
|
*key = KEYC_NONE;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (mtd->offset + y < mtd->line_size) {
|
if (mtd->offset + y < mtd->line_size) {
|
||||||
mtd->current = mtd->offset + y;
|
if (*key == KEYC_MOUSEDOWN1_PANE ||
|
||||||
*key = '\r';
|
*key == KEYC_DOUBLECLICK1_PANE)
|
||||||
return (0);
|
mtd->current = mtd->offset + y;
|
||||||
}
|
if (*key == KEYC_DOUBLECLICK1_PANE)
|
||||||
|
*key = '\r';
|
||||||
|
else
|
||||||
|
*key = KEYC_NONE;
|
||||||
|
} else
|
||||||
|
*key = KEYC_NONE;
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
line = &mtd->line_list[mtd->current];
|
line = &mtd->line_list[mtd->current];
|
||||||
@@ -770,15 +820,18 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
|
|||||||
switch (*key) {
|
switch (*key) {
|
||||||
case 'q':
|
case 'q':
|
||||||
case '\033': /* Escape */
|
case '\033': /* Escape */
|
||||||
|
case '\007': /* C-g */
|
||||||
return (1);
|
return (1);
|
||||||
case KEYC_UP:
|
case KEYC_UP:
|
||||||
case 'k':
|
case 'k':
|
||||||
case KEYC_WHEELUP_PANE:
|
case KEYC_WHEELUP_PANE:
|
||||||
|
case '\020': /* C-p */
|
||||||
mode_tree_up(mtd, 1);
|
mode_tree_up(mtd, 1);
|
||||||
break;
|
break;
|
||||||
case KEYC_DOWN:
|
case KEYC_DOWN:
|
||||||
case 'j':
|
case 'j':
|
||||||
case KEYC_WHEELDOWN_PANE:
|
case KEYC_WHEELDOWN_PANE:
|
||||||
|
case '\016': /* C-n */
|
||||||
mode_tree_down(mtd, 1);
|
mode_tree_down(mtd, 1);
|
||||||
break;
|
break;
|
||||||
case KEYC_PPAGE:
|
case KEYC_PPAGE:
|
||||||
@@ -844,6 +897,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
|
|||||||
mode_tree_build(mtd);
|
mode_tree_build(mtd);
|
||||||
break;
|
break;
|
||||||
case KEYC_LEFT:
|
case KEYC_LEFT:
|
||||||
|
case 'h':
|
||||||
case '-':
|
case '-':
|
||||||
if (line->flat || !current->expanded)
|
if (line->flat || !current->expanded)
|
||||||
current = current->parent;
|
current = current->parent;
|
||||||
@@ -856,6 +910,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KEYC_RIGHT:
|
case KEYC_RIGHT:
|
||||||
|
case 'l':
|
||||||
case '+':
|
case '+':
|
||||||
if (line->flat || current->expanded)
|
if (line->flat || current->expanded)
|
||||||
mode_tree_down(mtd, 0);
|
mode_tree_down(mtd, 0);
|
||||||
|
|||||||
22
notify.c
22
notify.c
@@ -35,7 +35,7 @@ struct notify_entry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
notify_hook(struct cmdq_item *item, struct notify_entry *ne)
|
notify_hook1(struct cmdq_item *item, struct notify_entry *ne)
|
||||||
{
|
{
|
||||||
struct cmd_find_state fs;
|
struct cmd_find_state fs;
|
||||||
struct hook *hook;
|
struct hook *hook;
|
||||||
@@ -101,7 +101,7 @@ notify_callback(struct cmdq_item *item, void *data)
|
|||||||
if (strcmp(ne->name, "session-window-changed") == 0)
|
if (strcmp(ne->name, "session-window-changed") == 0)
|
||||||
control_notify_session_window_changed(ne->session);
|
control_notify_session_window_changed(ne->session);
|
||||||
|
|
||||||
notify_hook(item, ne);
|
notify_hook1(item, ne);
|
||||||
|
|
||||||
if (ne->client != NULL)
|
if (ne->client != NULL)
|
||||||
server_client_unref(ne->client);
|
server_client_unref(ne->client);
|
||||||
@@ -153,6 +153,24 @@ notify_add(const char *name, struct cmd_find_state *fs, struct client *c,
|
|||||||
cmdq_append(NULL, new_item);
|
cmdq_append(NULL, new_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
notify_hook(struct cmdq_item *item, const char *name)
|
||||||
|
{
|
||||||
|
struct notify_entry ne;
|
||||||
|
|
||||||
|
memset(&ne, 0, sizeof ne);
|
||||||
|
|
||||||
|
ne.name = name;
|
||||||
|
cmd_find_copy_state(&ne.fs, &item->target);
|
||||||
|
|
||||||
|
ne.client = item->client;
|
||||||
|
ne.session = item->target.s;
|
||||||
|
ne.window = item->target.w;
|
||||||
|
ne.pane = item->target.wp->id;
|
||||||
|
|
||||||
|
notify_hook1(item, &ne);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
notify_input(struct window_pane *wp, struct evbuffer *input)
|
notify_input(struct window_pane *wp, struct evbuffer *input)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -96,6 +96,12 @@ const struct options_table_entry options_table[] = {
|
|||||||
.default_num = 500
|
.default_num = 500
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{ .name = "exit-empty",
|
||||||
|
.type = OPTIONS_TABLE_FLAG,
|
||||||
|
.scope = OPTIONS_TABLE_SERVER,
|
||||||
|
.default_num = 1
|
||||||
|
},
|
||||||
|
|
||||||
{ .name = "exit-unattached",
|
{ .name = "exit-unattached",
|
||||||
.type = OPTIONS_TABLE_FLAG,
|
.type = OPTIONS_TABLE_FLAG,
|
||||||
.scope = OPTIONS_TABLE_SERVER,
|
.scope = OPTIONS_TABLE_SERVER,
|
||||||
@@ -507,8 +513,8 @@ const struct options_table_entry options_table[] = {
|
|||||||
{ .name = "update-environment",
|
{ .name = "update-environment",
|
||||||
.type = OPTIONS_TABLE_ARRAY,
|
.type = OPTIONS_TABLE_ARRAY,
|
||||||
.scope = OPTIONS_TABLE_SESSION,
|
.scope = OPTIONS_TABLE_SESSION,
|
||||||
.default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
|
.default_str = "DISPLAY KRB5CCNAME SSH_ASKPASS SSH_AUTH_SOCK "
|
||||||
"SSH_CONNECTION WINDOWID XAUTHORITY"
|
"SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
|
||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "visual-activity",
|
{ .name = "visual-activity",
|
||||||
@@ -547,7 +553,7 @@ const struct options_table_entry options_table[] = {
|
|||||||
{ .name = "allow-rename",
|
{ .name = "allow-rename",
|
||||||
.type = OPTIONS_TABLE_FLAG,
|
.type = OPTIONS_TABLE_FLAG,
|
||||||
.scope = OPTIONS_TABLE_WINDOW,
|
.scope = OPTIONS_TABLE_WINDOW,
|
||||||
.default_num = 1
|
.default_num = 0
|
||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "alternate-screen",
|
{ .name = "alternate-screen",
|
||||||
|
|||||||
@@ -88,11 +88,17 @@ osdep_get_cwd(int fd)
|
|||||||
struct event_base *
|
struct event_base *
|
||||||
osdep_event_init(void)
|
osdep_event_init(void)
|
||||||
{
|
{
|
||||||
|
struct event_base *base;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* On OS X, kqueue and poll are both completely broken and don't
|
* On OS X, kqueue and poll are both completely broken and don't
|
||||||
* work on anything except socket file descriptors (yes, really).
|
* work on anything except socket file descriptors (yes, really).
|
||||||
*/
|
*/
|
||||||
setenv("EVENT_NOKQUEUE", "1", 1);
|
setenv("EVENT_NOKQUEUE", "1", 1);
|
||||||
setenv("EVENT_NOPOLL", "1", 1);
|
setenv("EVENT_NOPOLL", "1", 1);
|
||||||
return (event_init());
|
|
||||||
|
base = event_init();
|
||||||
|
unsetenv("EVENT_NOKQUEUE");
|
||||||
|
unsetenv("EVENT_NOPOLL");
|
||||||
|
return (base);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,10 +193,15 @@ osdep_get_cwd(int fd)
|
|||||||
struct event_base *
|
struct event_base *
|
||||||
osdep_event_init(void)
|
osdep_event_init(void)
|
||||||
{
|
{
|
||||||
|
struct event_base *base;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* On some versions of FreeBSD, kqueue doesn't work properly on tty
|
* On some versions of FreeBSD, kqueue doesn't work properly on tty
|
||||||
* file descriptors. This is fixed in recent FreeBSD versions.
|
* file descriptors. This is fixed in recent FreeBSD versions.
|
||||||
*/
|
*/
|
||||||
setenv("EVENT_NOKQUEUE", "1", 1);
|
setenv("EVENT_NOKQUEUE", "1", 1);
|
||||||
return (event_init());
|
|
||||||
|
base = event_init();
|
||||||
|
unsetenv("EVENT_NOKQUEUE");
|
||||||
|
return (base);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,12 @@ osdep_get_cwd(int fd)
|
|||||||
struct event_base *
|
struct event_base *
|
||||||
osdep_event_init(void)
|
osdep_event_init(void)
|
||||||
{
|
{
|
||||||
|
struct event_base *base;
|
||||||
|
|
||||||
/* On Linux, epoll doesn't work on /dev/null (yes, really). */
|
/* On Linux, epoll doesn't work on /dev/null (yes, really). */
|
||||||
setenv("EVENT_NOEPOLL", "1", 1);
|
setenv("EVENT_NOEPOLL", "1", 1);
|
||||||
return (event_init());
|
|
||||||
|
base = event_init();
|
||||||
|
unsetenv("EVENT_NOEPOLL");
|
||||||
|
return (base);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ $TMUX kill-server 2>/dev/null
|
|||||||
|
|
||||||
TMP=$(mktemp)
|
TMP=$(mktemp)
|
||||||
OUT=$(mktemp)
|
OUT=$(mktemp)
|
||||||
trap "rm -f $TMP $OUT" 0 1 15
|
#trap "rm -f $TMP $OUT" 0 1 15
|
||||||
|
|
||||||
$TMUX -f/dev/null new -d || exit 1
|
$TMUX -f/dev/null new -d || exit 1
|
||||||
sleep 1
|
sleep 1
|
||||||
@@ -23,7 +23,7 @@ refresh -C 100,50
|
|||||||
ls -F':#{session_width} #{session_height}'
|
ls -F':#{session_width} #{session_height}'
|
||||||
EOF
|
EOF
|
||||||
grep ^: $TMP >$OUT
|
grep ^: $TMP >$OUT
|
||||||
printf ":80 24\n:100 50\n"|cmp -s $OUT || exit 1
|
printf ":80 24\n:100 50\n"|cmp -s $OUT - || exit 1
|
||||||
$TMUX kill-server 2>/dev/null
|
$TMUX kill-server 2>/dev/null
|
||||||
|
|
||||||
$TMUX -f/dev/null new -d || exit 1
|
$TMUX -f/dev/null new -d || exit 1
|
||||||
@@ -34,7 +34,7 @@ refresh -C 80,24
|
|||||||
ls -F':#{session_width} #{session_height}'
|
ls -F':#{session_width} #{session_height}'
|
||||||
EOF
|
EOF
|
||||||
grep ^: $TMP >$OUT
|
grep ^: $TMP >$OUT
|
||||||
printf ":80 24\n:80 24\n"|cmp -s $OUT || exit 1
|
printf ":80 24\n:80 24\n"|cmp -s $OUT - || exit 1
|
||||||
$TMUX kill-server 2>/dev/null
|
$TMUX kill-server 2>/dev/null
|
||||||
|
|
||||||
cat <<EOF|$TMUX -C new -x 100 -y 50 >$TMP
|
cat <<EOF|$TMUX -C new -x 100 -y 50 >$TMP
|
||||||
@@ -43,7 +43,7 @@ refresh -C 80,24
|
|||||||
ls -F':#{session_width} #{session_height}'
|
ls -F':#{session_width} #{session_height}'
|
||||||
EOF
|
EOF
|
||||||
grep ^: $TMP >$OUT
|
grep ^: $TMP >$OUT
|
||||||
printf ":100 50\n:80 24\n"|cmp -s $OUT || exit 1
|
printf ":100 50\n:80 24\n"|cmp -s $OUT - || exit 1
|
||||||
$TMUX kill-server 2>/dev/null
|
$TMUX kill-server 2>/dev/null
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
183
regress/format-strings.sh
Normal file
183
regress/format-strings.sh
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Tests of formats as described in tmux(1) FORMATS
|
||||||
|
|
||||||
|
PATH=/bin:/usr/bin
|
||||||
|
TERM=screen
|
||||||
|
|
||||||
|
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
|
||||||
|
TMUX="$TEST_TMUX -Ltest"
|
||||||
|
|
||||||
|
# test_format $format $expected_result
|
||||||
|
test_format()
|
||||||
|
{
|
||||||
|
fmt="$1"
|
||||||
|
exp="$2"
|
||||||
|
|
||||||
|
out=$($TMUX display-message -p "$fmt")
|
||||||
|
|
||||||
|
if [ "$out" != "$exp" ]; then
|
||||||
|
echo "Format test failed for '$fmt'."
|
||||||
|
echo "Expected: '$exp'"
|
||||||
|
echo "But got '$out'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# test_conditional_with_pane_in_mode $format $exp1 $exp2
|
||||||
|
#
|
||||||
|
# Tests the format string $format to yield $exp1 if #{pane_in_mode} is true and
|
||||||
|
# $exp2 when #{pane_in_mode} is false.
|
||||||
|
test_conditional_with_pane_in_mode()
|
||||||
|
{
|
||||||
|
fmt="$1"
|
||||||
|
exp_true="$2"
|
||||||
|
exp_false="$3"
|
||||||
|
|
||||||
|
$TMUX copy-mode # enter copy mode
|
||||||
|
test_format "$fmt" "$exp_true"
|
||||||
|
$TMUX send-keys -X cancel # leave copy mode
|
||||||
|
test_format "$fmt" "$exp_false"
|
||||||
|
}
|
||||||
|
|
||||||
|
# test_conditional_with_session_name #format $exp_summer $exp_winter
|
||||||
|
#
|
||||||
|
# Tests the format string $format to yield $exp_summer if the session name is
|
||||||
|
# 'Summer' and $exp_winter if the session name is 'Winter'.
|
||||||
|
test_conditional_with_session_name()
|
||||||
|
{
|
||||||
|
fmt="$1"
|
||||||
|
exp_summer="$2"
|
||||||
|
exp_winter="$3"
|
||||||
|
|
||||||
|
$TMUX rename-session "Summer"
|
||||||
|
test_format "$fmt" "$exp_summer"
|
||||||
|
$TMUX rename-session "Winter"
|
||||||
|
test_format "$fmt" "$exp_winter"
|
||||||
|
$TMUX rename-session "Summer" # restore default
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$TMUX kill-server 2>/dev/null
|
||||||
|
$TMUX -f/dev/null new-session -d || exit 1
|
||||||
|
$TMUX rename-session "Summer" || exit 1 # used later in conditionals
|
||||||
|
|
||||||
|
# Plain string without substitutions et al
|
||||||
|
test_format "abc xyz" "abc xyz"
|
||||||
|
|
||||||
|
# Test basic escapes for "#", "{", "#{" "}", "#}", ","
|
||||||
|
test_format "##" "#"
|
||||||
|
test_format "#," ","
|
||||||
|
test_format "{" "{"
|
||||||
|
test_format "##{" "#{"
|
||||||
|
test_format "#}" "}"
|
||||||
|
test_format "###}" "#}" # not a "basic" one but interesting nevertheless
|
||||||
|
|
||||||
|
# Simple expansion
|
||||||
|
test_format "#{pane_in_mode}" "0"
|
||||||
|
|
||||||
|
# Simple conditionals
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,xyz}" "abc" "xyz"
|
||||||
|
|
||||||
|
# Expansion in conditionals
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,#{session_name},xyz}" "Summer" "xyz"
|
||||||
|
|
||||||
|
# Basic escapes in conditionals
|
||||||
|
# First argument
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,##,xyz}" "#" "xyz"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,#,,xyz}" "," "xyz"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,{,xyz}" "{" "xyz"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,##{,xyz}" "#{" "xyz"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,#},xyz}" "}" "xyz"
|
||||||
|
# not a "basic" one but interesting nevertheless
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,###},xyz}" "#}" "xyz"
|
||||||
|
# Second argument
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,##}" "abc" "#"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,#,}" "abc" ","
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,{}" "abc" "{"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,##{}" "abc" "#{"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,#}}" "abc" "}"
|
||||||
|
# not a "basic" one but interesting nevertheless
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,###}}" "abc" "#}"
|
||||||
|
# mixed
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,{,#}}" "{" "}"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,#},{}" "}" "{"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,##{,###}}" "#{" "#}"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,###},##{}" "#}" "#{"
|
||||||
|
|
||||||
|
# Conditionals split on the second comma (this is not documented)
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,xyz,bonus}" "abc" "xyz,bonus"
|
||||||
|
|
||||||
|
# Curly brackets {...} do not capture a comma inside of conditionals as the
|
||||||
|
# conditional ends on the first '}'
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,{abc,xyz},bonus}" "{abc,bonus}" "xyz,bonus}"
|
||||||
|
|
||||||
|
# Substitutions '#{...}' capture the comma
|
||||||
|
# invalid format: #{abc,xyz} is not a known variable name.
|
||||||
|
#test_conditional_with_pane_in_mode "#{?pane_in_mode,#{abc,xyz},bonus}" "" "bonus"
|
||||||
|
|
||||||
|
# Parenthesis (...) do not captura a comma
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,(abc,xyz),bonus}" "(abc" "xyz),bonus"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,(abc#,xyz),bonus}" "(abc,xyz)" "bonus"
|
||||||
|
|
||||||
|
# Brackets [...] do not captura a comma
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,[abc,xyz],bonus}" "[abc" "xyz],bonus"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,[abc#,xyz],bonus}" "[abc,xyz]" "bonus"
|
||||||
|
|
||||||
|
|
||||||
|
# Escape comma inside of #(...)
|
||||||
|
# Note: #() commands are run asynchronous and are substituted with result of the
|
||||||
|
# *previous* run or a placeholder (like "<'echo ,' not ready") if the command
|
||||||
|
# has not been run before. The format is updated as soon as the command
|
||||||
|
# finishes. As we are printing the message only once it never gets updated
|
||||||
|
# and the displayed message is "<'echo ,' not ready>"
|
||||||
|
test_format "#{?pane_in_mode,#(echo #,),xyz}" "xyz"
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,#(echo #,),xyz}" "<'echo ,' not ready>" "xyz"
|
||||||
|
# This caching does not work :-(
|
||||||
|
#$TMUX display-message -p "#(echo #,)" > /dev/null
|
||||||
|
#test_conditional_with_pane_in_mode "#{?pane_in_mode,#(echo #,),xyz}" "," "xyz"
|
||||||
|
#test_conditional_with_pane_in_mode "#{?pane_in_mode,#(echo #,),xyz}" "," "xyz"
|
||||||
|
|
||||||
|
# invalid format: '#(' is not closed in the first argument of #{?,,}.
|
||||||
|
#test_conditional_with_pane_in_mode "#{?pane_in_mode,#(echo ,),xyz}" "" "),xyz"
|
||||||
|
|
||||||
|
# Escape comma inside of #[...]
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,#[fg=default#,bg=default]abc,xyz}" "#[fg=default,bg=default]abc" "xyz"
|
||||||
|
# invalid format: '#[' is not closed in the first argument of #{?,,}
|
||||||
|
#test_conditional_with_pane_in_mode "#{?pane_in_mode,#[fg=default,bg=default]abc,xyz}" "" "bg=default]abc,xyz"
|
||||||
|
|
||||||
|
# Conditionals with comparison
|
||||||
|
test_conditional_with_session_name "#{?#{==:#{session_name},Summer},abc,xyz}" "abc" "xyz"
|
||||||
|
# Conditionals with comparison and escaped commas
|
||||||
|
$TMUX rename-session ","
|
||||||
|
test_format "#{?#{==:#,,#{session_name}},abc,xyz}" "abc"
|
||||||
|
$TMUX rename-session "Summer" # reset to default
|
||||||
|
|
||||||
|
# Conditional in conditional
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,#{?#{==:#{session_name},Summer},ABC,XYZ},xyz}" "ABC" "xyz"
|
||||||
|
test_conditional_with_session_name "#{?pane_in_mode,#{?#{==:#{session_name},Summer},ABC,XYZ},xyz}" "xyz" "xyz"
|
||||||
|
|
||||||
|
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,#{?#{==:#{session_name},Summer},ABC,XYZ}}" "abc" "ABC"
|
||||||
|
test_conditional_with_session_name "#{?pane_in_mode,abc,#{?#{==:#{session_name},Summer},ABC,XYZ}}" "ABC" "XYZ"
|
||||||
|
|
||||||
|
# Some fancy stackings
|
||||||
|
test_conditional_with_pane_in_mode "#{?#{==:#{?pane_in_mode,#{session_name},#(echo Spring)},Summer},abc,xyz}" "abc" "xyz"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Format test for the literal option
|
||||||
|
# Note: The behavior for #{l:...} with escapes is sometimes weird as #{l:...}
|
||||||
|
# respects the escapes.
|
||||||
|
test_format "#{l:#{}}" "#{}"
|
||||||
|
test_format "#{l:#{pane_in_mode}}" "#{pane_in_mode}"
|
||||||
|
test_format "#{l:#{?pane_in_mode,#{?#{==:#{session_name},Summer},ABC,XYZ},xyz}}" "#{?pane_in_mode,#{?#{==:#{session_name},Summer},ABC,XYZ},xyz}"
|
||||||
|
|
||||||
|
# With escapes (which escape but are returned literally)
|
||||||
|
test_format "#{l:##{}" "##{"
|
||||||
|
test_format "#{l:#{#}}}" "#{#}}"
|
||||||
|
|
||||||
|
# Invalid formats:
|
||||||
|
#test_format "#{l:#{}" ""
|
||||||
|
#test_format "#{l:#{#}}" ""
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -15,13 +15,13 @@ trap "rm -f $TMP" 0 1 15
|
|||||||
$TMUX -f/dev/null new -d </dev/null || exit 1
|
$TMUX -f/dev/null new -d </dev/null || exit 1
|
||||||
sleep 1
|
sleep 1
|
||||||
$TMUX ls -F "#{session_width} #{session_height}" >$TMP
|
$TMUX ls -F "#{session_width} #{session_height}" >$TMP
|
||||||
printf "80 24\n"|cmp -s $TMP || exit 1
|
printf "80 24\n"|cmp -s $TMP - || exit 1
|
||||||
$TMUX kill-server 2>/dev/null
|
$TMUX kill-server 2>/dev/null
|
||||||
|
|
||||||
$TMUX -f/dev/null new -d -x 100 -y 50 </dev/null || exit 1
|
$TMUX -f/dev/null new -d -x 100 -y 50 </dev/null || exit 1
|
||||||
sleep 1
|
sleep 1
|
||||||
$TMUX ls -F "#{session_width} #{session_height}" >$TMP
|
$TMUX ls -F "#{session_width} #{session_height}" >$TMP
|
||||||
printf "100 50\n"|cmp -s $TMP || exit 1
|
printf "100 50\n"|cmp -s $TMP - || exit 1
|
||||||
$TMUX kill-server 2>/dev/null
|
$TMUX kill-server 2>/dev/null
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
20
resize.c
20
resize.c
@@ -49,11 +49,11 @@ recalculate_sizes(void)
|
|||||||
struct client *c;
|
struct client *c;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int ssx, ssy, has, limit;
|
u_int ssx, ssy, has, limit, lines;
|
||||||
int flag, has_status, is_zoomed, forced;
|
int flag, is_zoomed, forced;
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
has_status = options_get_number(s->options, "status");
|
lines = status_line_size(s);
|
||||||
|
|
||||||
s->attached = 0;
|
s->attached = 0;
|
||||||
ssx = ssy = UINT_MAX;
|
ssx = ssy = UINT_MAX;
|
||||||
@@ -66,10 +66,14 @@ recalculate_sizes(void)
|
|||||||
if (c->session == s) {
|
if (c->session == s) {
|
||||||
if (c->tty.sx < ssx)
|
if (c->tty.sx < ssx)
|
||||||
ssx = c->tty.sx;
|
ssx = c->tty.sx;
|
||||||
if (has_status &&
|
c->flags &= ~CLIENT_STATUSOFF;
|
||||||
|
if (lines != 0 && lines + PANE_MINIMUM > c->tty.sy)
|
||||||
|
c->flags |= CLIENT_STATUSOFF;
|
||||||
|
if ((~c->flags & CLIENT_STATUSOFF) &&
|
||||||
!(c->flags & CLIENT_CONTROL) &&
|
!(c->flags & CLIENT_CONTROL) &&
|
||||||
c->tty.sy > 1 && c->tty.sy - 1 < ssy)
|
c->tty.sy > lines &&
|
||||||
ssy = c->tty.sy - 1;
|
c->tty.sy - lines < ssy)
|
||||||
|
ssy = c->tty.sy - lines;
|
||||||
else if (c->tty.sy < ssy)
|
else if (c->tty.sy < ssy)
|
||||||
ssy = c->tty.sy;
|
ssy = c->tty.sy;
|
||||||
s->attached++;
|
s->attached++;
|
||||||
@@ -81,8 +85,8 @@ recalculate_sizes(void)
|
|||||||
}
|
}
|
||||||
s->flags &= ~SESSION_UNATTACHED;
|
s->flags &= ~SESSION_UNATTACHED;
|
||||||
|
|
||||||
if (has_status && ssy == 0)
|
if (lines != 0 && ssy == 0)
|
||||||
ssy = 1;
|
ssy = lines;
|
||||||
|
|
||||||
if (s->sx == ssx && s->sy == ssy)
|
if (s->sx == ssx && s->sy == ssy)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
203
screen-redraw.c
203
screen-redraw.c
@@ -18,10 +18,23 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
|
struct screen_redraw_ctx {
|
||||||
|
struct client *c;
|
||||||
|
|
||||||
|
u_int lines;
|
||||||
|
int top;
|
||||||
|
|
||||||
|
int pane_status;
|
||||||
|
|
||||||
|
u_int sx;
|
||||||
|
u_int sy;
|
||||||
|
};
|
||||||
|
|
||||||
static int screen_redraw_cell_border1(struct window_pane *, u_int, u_int);
|
static int screen_redraw_cell_border1(struct window_pane *, u_int, u_int);
|
||||||
static int screen_redraw_cell_border(struct client *, u_int, u_int);
|
static int screen_redraw_cell_border(struct client *, u_int, u_int);
|
||||||
static int screen_redraw_check_cell(struct client *, u_int, u_int, int,
|
static int screen_redraw_check_cell(struct client *, u_int, u_int, int,
|
||||||
@@ -33,11 +46,11 @@ static int screen_redraw_make_pane_status(struct client *, struct window *,
|
|||||||
struct window_pane *);
|
struct window_pane *);
|
||||||
static void screen_redraw_draw_pane_status(struct client *, int);
|
static void screen_redraw_draw_pane_status(struct client *, int);
|
||||||
|
|
||||||
static void screen_redraw_draw_borders(struct client *, int, int, u_int);
|
static void screen_redraw_draw_borders(struct screen_redraw_ctx *);
|
||||||
static void screen_redraw_draw_panes(struct client *, u_int);
|
static void screen_redraw_draw_panes(struct screen_redraw_ctx *);
|
||||||
static void screen_redraw_draw_status(struct client *, u_int);
|
static void screen_redraw_draw_status(struct screen_redraw_ctx *);
|
||||||
static void screen_redraw_draw_number(struct client *, struct window_pane *,
|
static void screen_redraw_draw_number(struct screen_redraw_ctx *,
|
||||||
u_int);
|
struct window_pane *);
|
||||||
|
|
||||||
#define CELL_INSIDE 0
|
#define CELL_INSIDE 0
|
||||||
#define CELL_LEFTRIGHT 1
|
#define CELL_LEFTRIGHT 1
|
||||||
@@ -299,6 +312,7 @@ screen_redraw_make_pane_status(struct client *c, struct window *w,
|
|||||||
screen_write_cnputs(&ctx, outlen, &gc, "%s", out);
|
screen_write_cnputs(&ctx, outlen, &gc, "%s", out);
|
||||||
screen_write_stop(&ctx);
|
screen_write_stop(&ctx);
|
||||||
|
|
||||||
|
free(out);
|
||||||
format_free(ft);
|
format_free(ft);
|
||||||
|
|
||||||
wp->status_size = outlen;
|
wp->status_size = outlen;
|
||||||
@@ -373,40 +387,44 @@ void
|
|||||||
screen_redraw_screen(struct client *c, int draw_panes, int draw_status,
|
screen_redraw_screen(struct client *c, int draw_panes, int draw_status,
|
||||||
int draw_borders)
|
int draw_borders)
|
||||||
{
|
{
|
||||||
struct options *oo = c->session->options;
|
struct options *oo = c->session->options;
|
||||||
struct tty *tty = &c->tty;
|
struct tty *tty = &c->tty;
|
||||||
struct window *w = c->session->curw->window;
|
struct window *w = c->session->curw->window;
|
||||||
struct options *wo = w->options;
|
struct options *wo = w->options;
|
||||||
u_int top;
|
struct screen_redraw_ctx ctx;
|
||||||
int status, pane_status, spos;
|
|
||||||
|
|
||||||
/* Suspended clients should not be updated. */
|
|
||||||
if (c->flags & CLIENT_SUSPENDED)
|
if (c->flags & CLIENT_SUSPENDED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Get status line, er, status. */
|
memset(&ctx, 0, sizeof ctx);
|
||||||
spos = options_get_number(oo, "status-position");
|
ctx.c = c;
|
||||||
if (c->message_string != NULL || c->prompt_string != NULL)
|
|
||||||
status = 1;
|
if (c->flags & CLIENT_STATUSOFF)
|
||||||
|
ctx.lines = 0;
|
||||||
else
|
else
|
||||||
status = options_get_number(oo, "status");
|
ctx.lines = status_line_size(c->session);
|
||||||
top = 0;
|
if (c->message_string != NULL || c->prompt_string != NULL)
|
||||||
if (status && spos == 0)
|
ctx.lines = (ctx.lines == 0) ? 1 : ctx.lines;
|
||||||
top = 1;
|
|
||||||
if (!status)
|
if (ctx.lines != 0 && options_get_number(oo, "status-position") == 0)
|
||||||
|
ctx.top = 1;
|
||||||
|
ctx.pane_status = options_get_number(wo, "pane-border-status");
|
||||||
|
|
||||||
|
ctx.sx = tty->sx;
|
||||||
|
ctx.sy = tty->sy - ctx.lines;
|
||||||
|
|
||||||
|
if (ctx.lines == 0)
|
||||||
draw_status = 0;
|
draw_status = 0;
|
||||||
|
|
||||||
/* Draw the elements. */
|
|
||||||
if (draw_borders) {
|
if (draw_borders) {
|
||||||
pane_status = options_get_number(wo, "pane-border-status");
|
if (ctx.pane_status != CELL_STATUS_OFF)
|
||||||
screen_redraw_draw_borders(c, status, pane_status, top);
|
screen_redraw_draw_pane_status(c, ctx.pane_status);
|
||||||
if (pane_status != CELL_STATUS_OFF)
|
screen_redraw_draw_borders(&ctx);
|
||||||
screen_redraw_draw_pane_status(c, pane_status);
|
|
||||||
}
|
}
|
||||||
if (draw_panes)
|
if (draw_panes)
|
||||||
screen_redraw_draw_panes(c, top);
|
screen_redraw_draw_panes(&ctx);
|
||||||
if (draw_status)
|
if (draw_status)
|
||||||
screen_redraw_draw_status(c, top);
|
screen_redraw_draw_status(&ctx);
|
||||||
tty_reset(tty);
|
tty_reset(tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,7 +439,7 @@ screen_redraw_pane(struct client *c, struct window_pane *wp)
|
|||||||
|
|
||||||
yoff = wp->yoff;
|
yoff = wp->yoff;
|
||||||
if (status_at_line(c) == 0)
|
if (status_at_line(c) == 0)
|
||||||
yoff++;
|
yoff += status_line_size(c->session);
|
||||||
|
|
||||||
log_debug("%s: redraw pane %%%u (at %u,%u)", c->name, wp->id,
|
log_debug("%s: redraw pane %%%u (at %u,%u)", c->name, wp->id,
|
||||||
wp->xoff, yoff);
|
wp->xoff, yoff);
|
||||||
@@ -431,25 +449,65 @@ screen_redraw_pane(struct client *c, struct window_pane *wp)
|
|||||||
tty_reset(&c->tty);
|
tty_reset(&c->tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Draw a border cell. */
|
||||||
|
static void
|
||||||
|
screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int x, u_int y,
|
||||||
|
int small, u_int msgx, u_int msgy, struct grid_cell *m_active_gc,
|
||||||
|
struct grid_cell *active_gc, struct grid_cell *m_other_gc,
|
||||||
|
struct grid_cell *other_gc)
|
||||||
|
{
|
||||||
|
struct client *c = ctx->c;
|
||||||
|
struct session *s = c->session;
|
||||||
|
struct window *w = s->curw->window;
|
||||||
|
struct tty *tty = &c->tty;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct window_pane *active = w->active;
|
||||||
|
struct window_pane *marked = marked_pane.wp;
|
||||||
|
u_int type;
|
||||||
|
int flag, pane_status = ctx->pane_status;
|
||||||
|
|
||||||
|
type = screen_redraw_check_cell(c, x, y, pane_status, &wp);
|
||||||
|
if (type == CELL_INSIDE)
|
||||||
|
return;
|
||||||
|
if (type == CELL_OUTSIDE && small && x > msgx && y == msgy)
|
||||||
|
return;
|
||||||
|
flag = screen_redraw_check_is(x, y, type, pane_status, w, active, wp);
|
||||||
|
|
||||||
|
if (server_is_marked(s, s->curw, marked_pane.wp) &&
|
||||||
|
screen_redraw_check_is(x, y, type, pane_status, w, marked, wp)) {
|
||||||
|
if (flag)
|
||||||
|
tty_attributes(tty, m_active_gc, NULL);
|
||||||
|
else
|
||||||
|
tty_attributes(tty, m_other_gc, NULL);
|
||||||
|
} else if (flag)
|
||||||
|
tty_attributes(tty, active_gc, NULL);
|
||||||
|
else
|
||||||
|
tty_attributes(tty, other_gc, NULL);
|
||||||
|
if (ctx->top)
|
||||||
|
tty_cursor(tty, x, ctx->lines + y);
|
||||||
|
else
|
||||||
|
tty_cursor(tty, x, y);
|
||||||
|
tty_putc(tty, CELL_BORDERS[type]);
|
||||||
|
}
|
||||||
|
|
||||||
/* Draw the borders. */
|
/* Draw the borders. */
|
||||||
static void
|
static void
|
||||||
screen_redraw_draw_borders(struct client *c, int status, int pane_status,
|
screen_redraw_draw_borders(struct screen_redraw_ctx *ctx)
|
||||||
u_int top)
|
|
||||||
{
|
{
|
||||||
|
struct client *c = ctx->c;
|
||||||
struct session *s = c->session;
|
struct session *s = c->session;
|
||||||
struct window *w = s->curw->window;
|
struct window *w = s->curw->window;
|
||||||
struct options *oo = w->options;
|
struct options *oo = w->options;
|
||||||
struct tty *tty = &c->tty;
|
struct tty *tty = &c->tty;
|
||||||
struct window_pane *wp;
|
|
||||||
struct grid_cell m_active_gc, active_gc, m_other_gc, other_gc;
|
struct grid_cell m_active_gc, active_gc, m_other_gc, other_gc;
|
||||||
struct grid_cell msg_gc;
|
struct grid_cell msg_gc;
|
||||||
u_int i, j, type, msgx = 0, msgy = 0;
|
u_int i, j, msgx = 0, msgy = 0;
|
||||||
int active, small, flags;
|
int small, flags;
|
||||||
char msg[256];
|
char msg[256];
|
||||||
const char *tmp;
|
const char *tmp;
|
||||||
size_t msglen = 0;
|
size_t msglen = 0;
|
||||||
|
|
||||||
small = (tty->sy - status + top > w->sy) || (tty->sx > w->sx);
|
small = (ctx->sy + ctx->top > w->sy) || (ctx->sx > w->sx);
|
||||||
if (small) {
|
if (small) {
|
||||||
flags = w->flags & (WINDOW_FORCEWIDTH|WINDOW_FORCEHEIGHT);
|
flags = w->flags & (WINDOW_FORCEWIDTH|WINDOW_FORCEHEIGHT);
|
||||||
if (flags == (WINDOW_FORCEWIDTH|WINDOW_FORCEHEIGHT))
|
if (flags == (WINDOW_FORCEWIDTH|WINDOW_FORCEHEIGHT))
|
||||||
@@ -458,18 +516,20 @@ screen_redraw_draw_borders(struct client *c, int status, int pane_status,
|
|||||||
tmp = "force-width";
|
tmp = "force-width";
|
||||||
else if (flags == WINDOW_FORCEHEIGHT)
|
else if (flags == WINDOW_FORCEHEIGHT)
|
||||||
tmp = "force-height";
|
tmp = "force-height";
|
||||||
|
else if (c->flags & CLIENT_STATUSOFF)
|
||||||
|
tmp = "status line";
|
||||||
else
|
else
|
||||||
tmp = "a smaller client";
|
tmp = "a smaller client";
|
||||||
xsnprintf(msg, sizeof msg, "(size %ux%u from %s)",
|
xsnprintf(msg, sizeof msg, "(size %ux%u from %s)",
|
||||||
w->sx, w->sy, tmp);
|
w->sx, w->sy, tmp);
|
||||||
msglen = strlen(msg);
|
msglen = strlen(msg);
|
||||||
|
|
||||||
if (tty->sy - 1 - status + top > w->sy && tty->sx >= msglen) {
|
if (ctx->sy - 1 + ctx->top > w->sy && ctx->sx >= msglen) {
|
||||||
msgx = tty->sx - msglen;
|
msgx = ctx->sx - msglen;
|
||||||
msgy = tty->sy - 1 - status + top;
|
msgy = ctx->sy - 1 + ctx->top;
|
||||||
} else if (tty->sx - w->sx > msglen) {
|
} else if (ctx->sx - w->sx > msglen) {
|
||||||
msgx = tty->sx - msglen;
|
msgx = ctx->sx - msglen;
|
||||||
msgy = tty->sy - 1 - status + top;
|
msgy = ctx->sy - 1 + ctx->top;
|
||||||
} else
|
} else
|
||||||
small = 0;
|
small = 0;
|
||||||
}
|
}
|
||||||
@@ -483,30 +543,11 @@ screen_redraw_draw_borders(struct client *c, int status, int pane_status,
|
|||||||
memcpy(&m_active_gc, &active_gc, sizeof m_active_gc);
|
memcpy(&m_active_gc, &active_gc, sizeof m_active_gc);
|
||||||
m_active_gc.attr ^= GRID_ATTR_REVERSE;
|
m_active_gc.attr ^= GRID_ATTR_REVERSE;
|
||||||
|
|
||||||
for (j = 0; j < tty->sy - status; j++) {
|
for (j = 0; j < ctx->sy; j++) {
|
||||||
for (i = 0; i < tty->sx; i++) {
|
for (i = 0; i < ctx->sx; i++) {
|
||||||
type = screen_redraw_check_cell(c, i, j, pane_status,
|
screen_redraw_draw_borders_cell(ctx, i, j, small,
|
||||||
&wp);
|
msgx, msgy, &m_active_gc, &active_gc, &m_other_gc,
|
||||||
if (type == CELL_INSIDE)
|
&other_gc);
|
||||||
continue;
|
|
||||||
if (type == CELL_OUTSIDE && small &&
|
|
||||||
i > msgx && j == msgy)
|
|
||||||
continue;
|
|
||||||
active = screen_redraw_check_is(i, j, type, pane_status,
|
|
||||||
w, w->active, wp);
|
|
||||||
if (server_is_marked(s, s->curw, marked_pane.wp) &&
|
|
||||||
screen_redraw_check_is(i, j, type, pane_status, w,
|
|
||||||
marked_pane.wp, wp)) {
|
|
||||||
if (active)
|
|
||||||
tty_attributes(tty, &m_active_gc, NULL);
|
|
||||||
else
|
|
||||||
tty_attributes(tty, &m_other_gc, NULL);
|
|
||||||
} else if (active)
|
|
||||||
tty_attributes(tty, &active_gc, NULL);
|
|
||||||
else
|
|
||||||
tty_attributes(tty, &other_gc, NULL);
|
|
||||||
tty_cursor(tty, i, top + j);
|
|
||||||
tty_putc(tty, CELL_BORDERS[type]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,39 +561,49 @@ screen_redraw_draw_borders(struct client *c, int status, int pane_status,
|
|||||||
|
|
||||||
/* Draw the panes. */
|
/* Draw the panes. */
|
||||||
static void
|
static void
|
||||||
screen_redraw_draw_panes(struct client *c, u_int top)
|
screen_redraw_draw_panes(struct screen_redraw_ctx *ctx)
|
||||||
{
|
{
|
||||||
|
struct client *c = ctx->c;
|
||||||
struct window *w = c->session->curw->window;
|
struct window *w = c->session->curw->window;
|
||||||
struct tty *tty = &c->tty;
|
struct tty *tty = &c->tty;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int i;
|
u_int i, y;
|
||||||
|
|
||||||
|
if (ctx->top)
|
||||||
|
y = ctx->lines;
|
||||||
|
else
|
||||||
|
y = 0;
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
if (!window_pane_visible(wp))
|
if (!window_pane_visible(wp))
|
||||||
continue;
|
continue;
|
||||||
for (i = 0; i < wp->sy; i++)
|
for (i = 0; i < wp->sy; i++)
|
||||||
tty_draw_pane(tty, wp, i, wp->xoff, top + wp->yoff);
|
tty_draw_pane(tty, wp, i, wp->xoff, y + wp->yoff);
|
||||||
if (c->flags & CLIENT_IDENTIFY)
|
if (c->flags & CLIENT_IDENTIFY)
|
||||||
screen_redraw_draw_number(c, wp, top);
|
screen_redraw_draw_number(ctx, wp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw the status line. */
|
/* Draw the status line. */
|
||||||
static void
|
static void
|
||||||
screen_redraw_draw_status(struct client *c, u_int top)
|
screen_redraw_draw_status(struct screen_redraw_ctx *ctx)
|
||||||
{
|
{
|
||||||
|
struct client *c = ctx->c;
|
||||||
struct tty *tty = &c->tty;
|
struct tty *tty = &c->tty;
|
||||||
|
u_int i, y;
|
||||||
|
|
||||||
if (top)
|
if (ctx->top)
|
||||||
tty_draw_line(tty, NULL, &c->status, 0, 0, 0);
|
y = 0;
|
||||||
else
|
else
|
||||||
tty_draw_line(tty, NULL, &c->status, 0, 0, tty->sy - 1);
|
y = ctx->sy;
|
||||||
|
for (i = 0; i < ctx->lines; i++)
|
||||||
|
tty_draw_line(tty, NULL, &c->status.status, i, 0, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw number on a pane. */
|
/* Draw number on a pane. */
|
||||||
static void
|
static void
|
||||||
screen_redraw_draw_number(struct client *c, struct window_pane *wp, u_int top)
|
screen_redraw_draw_number(struct screen_redraw_ctx *ctx, struct window_pane *wp)
|
||||||
{
|
{
|
||||||
|
struct client *c = ctx->c;
|
||||||
struct tty *tty = &c->tty;
|
struct tty *tty = &c->tty;
|
||||||
struct session *s = c->session;
|
struct session *s = c->session;
|
||||||
struct options *oo = s->options;
|
struct options *oo = s->options;
|
||||||
@@ -575,8 +626,8 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp, u_int top)
|
|||||||
px = wp->sx / 2; py = wp->sy / 2;
|
px = wp->sx / 2; py = wp->sy / 2;
|
||||||
xoff = wp->xoff; yoff = wp->yoff;
|
xoff = wp->xoff; yoff = wp->yoff;
|
||||||
|
|
||||||
if (top)
|
if (ctx->top)
|
||||||
yoff++;
|
yoff += ctx->lines;
|
||||||
|
|
||||||
if (wp->sx < len * 6 || wp->sy < 5) {
|
if (wp->sx < len * 6 || wp->sy < 5) {
|
||||||
tty_cursor(tty, xoff + px - len / 2, yoff + py);
|
tty_cursor(tty, xoff + px - len / 2, yoff + py);
|
||||||
|
|||||||
103
screen-write.c
103
screen-write.c
@@ -351,11 +351,10 @@ screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
|
|||||||
free(msg);
|
free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy from another screen. */
|
/* Copy from another screen. Assumes target region is big enough. */
|
||||||
void
|
void
|
||||||
screen_write_copy(struct screen_write_ctx *ctx, struct screen *src, u_int px,
|
screen_write_copy(struct screen_write_ctx *ctx, struct screen *src, u_int px,
|
||||||
u_int py, u_int nx, u_int ny, bitstr_t *markbs,
|
u_int py, u_int nx, u_int ny, bitstr_t *mbs, const struct grid_cell *mgc)
|
||||||
const struct grid_cell *markgc)
|
|
||||||
{
|
{
|
||||||
struct screen *s = ctx->s;
|
struct screen *s = ctx->s;
|
||||||
struct grid *gd = src->grid;
|
struct grid *gd = src->grid;
|
||||||
@@ -371,22 +370,57 @@ screen_write_copy(struct screen_write_ctx *ctx, struct screen *src, u_int px,
|
|||||||
for (yy = py; yy < py + ny; yy++) {
|
for (yy = py; yy < py + ny; yy++) {
|
||||||
for (xx = px; xx < px + nx; xx++) {
|
for (xx = px; xx < px + nx; xx++) {
|
||||||
grid_get_cell(gd, xx, yy, &gc);
|
grid_get_cell(gd, xx, yy, &gc);
|
||||||
if (markbs != NULL) {
|
if (mbs != NULL) {
|
||||||
b = (yy * screen_size_x(src)) + xx;
|
b = (yy * screen_size_x(src)) + xx;
|
||||||
if (bit_test(markbs, b)) {
|
if (bit_test(mbs, b)) {
|
||||||
gc.attr = markgc->attr;
|
gc.attr = mgc->attr;
|
||||||
gc.fg = markgc->fg;
|
gc.fg = mgc->fg;
|
||||||
gc.bg = markgc->bg;
|
gc.bg = mgc->bg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
screen_write_cell(ctx, &gc);
|
if (xx + gc.data.width <= px + nx)
|
||||||
|
screen_write_cell(ctx, &gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
cy++;
|
cy++;
|
||||||
screen_write_cursormove(ctx, cx, cy);
|
screen_write_cursormove(ctx, cx, cy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy from another screen but without the selection stuff. Also assumes the
|
||||||
|
* target region is already big enough and already cleared.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
screen_write_fast_copy(struct screen_write_ctx *ctx, struct screen *src,
|
||||||
|
u_int px, u_int py, u_int nx, u_int ny)
|
||||||
|
{
|
||||||
|
struct screen *s = ctx->s;
|
||||||
|
struct grid *gd = src->grid;
|
||||||
|
struct grid_cell gc;
|
||||||
|
u_int xx, yy, cx, cy;
|
||||||
|
|
||||||
|
if (nx == 0 || ny == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cy = s->cy;
|
||||||
|
for (yy = py; yy < py + ny; yy++) {
|
||||||
|
if (yy >= gd->hsize + gd->sy)
|
||||||
|
break;
|
||||||
|
cx = s->cx;
|
||||||
|
for (xx = px; xx < px + nx; xx++) {
|
||||||
|
if (xx >= grid_get_line(gd, yy)->cellsize)
|
||||||
|
break;
|
||||||
|
grid_get_cell(gd, xx, yy, &gc);
|
||||||
|
if (xx + gc.data.width > px + nx)
|
||||||
|
break;
|
||||||
|
if (!grid_cells_equal(&gc, &grid_default_cell))
|
||||||
|
grid_view_set_cell(ctx->s->grid, cx, cy, &gc);
|
||||||
|
cx++;
|
||||||
|
}
|
||||||
|
cy++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Draw a horizontal line on screen. */
|
/* Draw a horizontal line on screen. */
|
||||||
void
|
void
|
||||||
screen_write_hline(struct screen_write_ctx *ctx, u_int nx, int left, int right)
|
screen_write_hline(struct screen_write_ctx *ctx, u_int nx, int left, int right)
|
||||||
@@ -428,7 +462,7 @@ screen_write_vline(struct screen_write_ctx *ctx, u_int ny, int top, int bottom)
|
|||||||
screen_write_cursormove(ctx, cx, cy + i);
|
screen_write_cursormove(ctx, cx, cy + i);
|
||||||
screen_write_putc(ctx, &gc, 'x');
|
screen_write_putc(ctx, &gc, 'x');
|
||||||
}
|
}
|
||||||
screen_write_cursormove(ctx, cx, cy + ny);
|
screen_write_cursormove(ctx, cx, cy + ny - 1);
|
||||||
screen_write_putc(ctx, &gc, bottom ? 'v' : 'x');
|
screen_write_putc(ctx, &gc, bottom ? 'v' : 'x');
|
||||||
|
|
||||||
screen_write_cursormove(ctx, cx, cy);
|
screen_write_cursormove(ctx, cx, cy);
|
||||||
@@ -471,7 +505,10 @@ screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny)
|
|||||||
screen_write_cursormove(ctx, cx, cy);
|
screen_write_cursormove(ctx, cx, cy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a preview version of a window. */
|
/*
|
||||||
|
* Write a preview version of a window. Assumes target area is big enough and
|
||||||
|
* already cleared.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
screen_write_preview(struct screen_write_ctx *ctx, struct screen *src, u_int nx,
|
screen_write_preview(struct screen_write_ctx *ctx, struct screen *src, u_int nx,
|
||||||
u_int ny)
|
u_int ny)
|
||||||
@@ -515,8 +552,7 @@ screen_write_preview(struct screen_write_ctx *ctx, struct screen *src, u_int nx,
|
|||||||
py = 0;
|
py = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_write_copy(ctx, src, px, src->grid->hsize + py, nx, ny, NULL,
|
screen_write_fast_copy(ctx, src, px, src->grid->hsize + py, nx, ny);
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (src->mode & MODE_CURSOR) {
|
if (src->mode & MODE_CURSOR) {
|
||||||
grid_view_get_cell(src->grid, src->cx, src->cy, &gc);
|
grid_view_get_cell(src->grid, src->cx, src->cy, &gc);
|
||||||
@@ -658,7 +694,7 @@ screen_write_backspace(struct screen_write_ctx *ctx)
|
|||||||
if (s->cx == 0) {
|
if (s->cx == 0) {
|
||||||
if (s->cy == 0)
|
if (s->cy == 0)
|
||||||
return;
|
return;
|
||||||
gl = &s->grid->linedata[s->grid->hsize + s->cy - 1];
|
gl = grid_get_line(s->grid, s->grid->hsize + s->cy - 1);
|
||||||
if (gl->flags & GRID_LINE_WRAPPED) {
|
if (gl->flags & GRID_LINE_WRAPPED) {
|
||||||
s->cy--;
|
s->cy--;
|
||||||
s->cx = screen_size_x(s) - 1;
|
s->cx = screen_size_x(s) - 1;
|
||||||
@@ -881,7 +917,7 @@ screen_write_clearline(struct screen_write_ctx *ctx, u_int bg)
|
|||||||
struct tty_ctx ttyctx;
|
struct tty_ctx ttyctx;
|
||||||
u_int sx = screen_size_x(s);
|
u_int sx = screen_size_x(s);
|
||||||
|
|
||||||
gl = &s->grid->linedata[s->grid->hsize + s->cy];
|
gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
|
||||||
if (gl->cellsize == 0 && bg == 8)
|
if (gl->cellsize == 0 && bg == 8)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -904,7 +940,7 @@ screen_write_clearendofline(struct screen_write_ctx *ctx, u_int bg)
|
|||||||
struct tty_ctx ttyctx;
|
struct tty_ctx ttyctx;
|
||||||
u_int sx = screen_size_x(s);
|
u_int sx = screen_size_x(s);
|
||||||
|
|
||||||
gl = &s->grid->linedata[s->grid->hsize + s->cy];
|
gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
|
||||||
if (s->cx > sx - 1 || (s->cx >= gl->cellsize && bg == 8))
|
if (s->cx > sx - 1 || (s->cx >= gl->cellsize && bg == 8))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1007,7 +1043,7 @@ screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped, u_int bg)
|
|||||||
struct grid *gd = s->grid;
|
struct grid *gd = s->grid;
|
||||||
struct grid_line *gl;
|
struct grid_line *gl;
|
||||||
|
|
||||||
gl = &gd->linedata[gd->hsize + s->cy];
|
gl = grid_get_line(gd, gd->hsize + s->cy);
|
||||||
if (wrapped)
|
if (wrapped)
|
||||||
gl->flags |= GRID_LINE_WRAPPED;
|
gl->flags |= GRID_LINE_WRAPPED;
|
||||||
else
|
else
|
||||||
@@ -1243,6 +1279,7 @@ screen_write_collect_end(struct screen_write_ctx *ctx)
|
|||||||
struct screen *s = ctx->s;
|
struct screen *s = ctx->s;
|
||||||
struct screen_write_collect_item *ci = ctx->item;
|
struct screen_write_collect_item *ci = ctx->item;
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
|
u_int xx;
|
||||||
|
|
||||||
if (ci->used == 0)
|
if (ci->used == 0)
|
||||||
return;
|
return;
|
||||||
@@ -1255,9 +1292,29 @@ screen_write_collect_end(struct screen_write_ctx *ctx)
|
|||||||
log_debug("%s: %u %s (at %u,%u)", __func__, ci->used, ci->data, s->cx,
|
log_debug("%s: %u %s (at %u,%u)", __func__, ci->used, ci->data, s->cx,
|
||||||
s->cy);
|
s->cy);
|
||||||
|
|
||||||
|
if (s->cx != 0) {
|
||||||
|
for (xx = s->cx; xx > 0; xx--) {
|
||||||
|
grid_view_get_cell(s->grid, xx, s->cy, &gc);
|
||||||
|
if (~gc.flags & GRID_FLAG_PADDING)
|
||||||
|
break;
|
||||||
|
grid_view_set_cell(s->grid, xx, s->cy,
|
||||||
|
&grid_default_cell);
|
||||||
|
}
|
||||||
|
if (gc.data.width > 1)
|
||||||
|
grid_view_set_cell(s->grid, xx, s->cy,
|
||||||
|
&grid_default_cell);
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(&gc, &ci->gc, sizeof gc);
|
memcpy(&gc, &ci->gc, sizeof gc);
|
||||||
grid_view_set_cells(s->grid, s->cx, s->cy, &gc, ci->data, ci->used);
|
grid_view_set_cells(s->grid, s->cx, s->cy, &gc, ci->data, ci->used);
|
||||||
s->cx += ci->used;
|
s->cx += ci->used;
|
||||||
|
|
||||||
|
for (xx = s->cx; xx < screen_size_x(s); xx++) {
|
||||||
|
grid_view_get_cell(s->grid, xx, s->cy, &gc);
|
||||||
|
if (~gc.flags & GRID_FLAG_PADDING)
|
||||||
|
break;
|
||||||
|
grid_view_set_cell(s->grid, xx, s->cy, &grid_default_cell);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write cell data, collecting if necessary. */
|
/* Write cell data, collecting if necessary. */
|
||||||
@@ -1278,7 +1335,7 @@ screen_write_collect_add(struct screen_write_ctx *ctx,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
collect = 1;
|
collect = 1;
|
||||||
if (gc->data.width != 1 || gc->data.size != 1)
|
if (gc->data.width != 1 || gc->data.size != 1 || *gc->data.data >= 0x7f)
|
||||||
collect = 0;
|
collect = 0;
|
||||||
else if (gc->attr & GRID_ATTR_CHARSET)
|
else if (gc->attr & GRID_ATTR_CHARSET)
|
||||||
collect = 0;
|
collect = 0;
|
||||||
@@ -1286,7 +1343,7 @@ screen_write_collect_add(struct screen_write_ctx *ctx,
|
|||||||
collect = 0;
|
collect = 0;
|
||||||
else if (s->mode & MODE_INSERT)
|
else if (s->mode & MODE_INSERT)
|
||||||
collect = 0;
|
collect = 0;
|
||||||
else if (s->sel.flag)
|
else if (s->sel != NULL)
|
||||||
collect = 0;
|
collect = 0;
|
||||||
if (!collect) {
|
if (!collect) {
|
||||||
screen_write_collect_end(ctx);
|
screen_write_collect_end(ctx);
|
||||||
@@ -1376,7 +1433,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
|
|||||||
screen_write_initctx(ctx, &ttyctx);
|
screen_write_initctx(ctx, &ttyctx);
|
||||||
|
|
||||||
/* Handle overwriting of UTF-8 characters. */
|
/* Handle overwriting of UTF-8 characters. */
|
||||||
gl = &s->grid->linedata[s->grid->hsize + s->cy];
|
gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
|
||||||
if (gl->flags & GRID_LINE_EXTENDED) {
|
if (gl->flags & GRID_LINE_EXTENDED) {
|
||||||
grid_view_get_cell(gd, s->cx, s->cy, &now_gc);
|
grid_view_get_cell(gd, s->cx, s->cy, &now_gc);
|
||||||
if (screen_write_overwrite(ctx, &now_gc, width))
|
if (screen_write_overwrite(ctx, &now_gc, width))
|
||||||
@@ -1388,6 +1445,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
|
|||||||
* already ensured there is enough room.
|
* already ensured there is enough room.
|
||||||
*/
|
*/
|
||||||
for (xx = s->cx + 1; xx < s->cx + width; xx++) {
|
for (xx = s->cx + 1; xx < s->cx + width; xx++) {
|
||||||
|
log_debug("%s: new padding at %u,%u", __func__, xx, s->cy);
|
||||||
grid_view_set_cell(gd, xx, s->cy, &screen_write_pad_cell);
|
grid_view_set_cell(gd, xx, s->cy, &screen_write_pad_cell);
|
||||||
skip = 0;
|
skip = 0;
|
||||||
}
|
}
|
||||||
@@ -1537,10 +1595,12 @@ screen_write_overwrite(struct screen_write_ctx *ctx, struct grid_cell *gc,
|
|||||||
grid_view_get_cell(gd, xx, s->cy, &tmp_gc);
|
grid_view_get_cell(gd, xx, s->cy, &tmp_gc);
|
||||||
if (~tmp_gc.flags & GRID_FLAG_PADDING)
|
if (~tmp_gc.flags & GRID_FLAG_PADDING)
|
||||||
break;
|
break;
|
||||||
|
log_debug("%s: padding at %u,%u", __func__, xx, s->cy);
|
||||||
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Overwrite the character at the start of this padding. */
|
/* Overwrite the character at the start of this padding. */
|
||||||
|
log_debug("%s: character at %u,%u", __func__, xx, s->cy);
|
||||||
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
@@ -1557,6 +1617,7 @@ screen_write_overwrite(struct screen_write_ctx *ctx, struct grid_cell *gc,
|
|||||||
grid_view_get_cell(gd, xx, s->cy, &tmp_gc);
|
grid_view_get_cell(gd, xx, s->cy, &tmp_gc);
|
||||||
if (~tmp_gc.flags & GRID_FLAG_PADDING)
|
if (~tmp_gc.flags & GRID_FLAG_PADDING)
|
||||||
break;
|
break;
|
||||||
|
log_debug("%s: overwrite at %u,%u", __func__, xx, s->cy);
|
||||||
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
149
screen.c
149
screen.c
@@ -24,21 +24,65 @@
|
|||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/* Selected area in screen. */
|
||||||
|
struct screen_sel {
|
||||||
|
int hidden;
|
||||||
|
int rectangle;
|
||||||
|
int modekeys;
|
||||||
|
|
||||||
|
u_int sx;
|
||||||
|
u_int sy;
|
||||||
|
|
||||||
|
u_int ex;
|
||||||
|
u_int ey;
|
||||||
|
|
||||||
|
struct grid_cell cell;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Entry on title stack. */
|
||||||
|
struct screen_title_entry {
|
||||||
|
char *text;
|
||||||
|
|
||||||
|
TAILQ_ENTRY(screen_title_entry) entry;
|
||||||
|
};
|
||||||
|
TAILQ_HEAD(screen_titles, screen_title_entry);
|
||||||
|
|
||||||
static void screen_resize_x(struct screen *, u_int);
|
static void screen_resize_x(struct screen *, u_int);
|
||||||
static void screen_resize_y(struct screen *, u_int);
|
static void screen_resize_y(struct screen *, u_int);
|
||||||
|
|
||||||
static void screen_reflow(struct screen *, u_int);
|
static void screen_reflow(struct screen *, u_int);
|
||||||
|
|
||||||
|
/* Free titles stack. */
|
||||||
|
static void
|
||||||
|
screen_free_titles(struct screen *s)
|
||||||
|
{
|
||||||
|
struct screen_title_entry *title_entry;
|
||||||
|
|
||||||
|
if (s->titles == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while ((title_entry = TAILQ_FIRST(s->titles)) != NULL) {
|
||||||
|
TAILQ_REMOVE(s->titles, title_entry, entry);
|
||||||
|
free(title_entry->text);
|
||||||
|
free(title_entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(s->titles);
|
||||||
|
s->titles = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create a new screen. */
|
/* Create a new screen. */
|
||||||
void
|
void
|
||||||
screen_init(struct screen *s, u_int sx, u_int sy, u_int hlimit)
|
screen_init(struct screen *s, u_int sx, u_int sy, u_int hlimit)
|
||||||
{
|
{
|
||||||
s->grid = grid_create(sx, sy, hlimit);
|
s->grid = grid_create(sx, sy, hlimit);
|
||||||
s->title = xstrdup("");
|
s->title = xstrdup("");
|
||||||
|
s->titles = NULL;
|
||||||
|
|
||||||
s->cstyle = 0;
|
s->cstyle = 0;
|
||||||
s->ccolour = xstrdup("");
|
s->ccolour = xstrdup("");
|
||||||
s->tabs = NULL;
|
s->tabs = NULL;
|
||||||
|
s->sel = NULL;
|
||||||
|
|
||||||
screen_reinit(s);
|
screen_reinit(s);
|
||||||
}
|
}
|
||||||
@@ -60,16 +104,21 @@ screen_reinit(struct screen *s)
|
|||||||
grid_clear_lines(s->grid, s->grid->hsize, s->grid->sy, 8);
|
grid_clear_lines(s->grid, s->grid->hsize, s->grid->sy, 8);
|
||||||
|
|
||||||
screen_clear_selection(s);
|
screen_clear_selection(s);
|
||||||
|
screen_free_titles(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destroy a screen. */
|
/* Destroy a screen. */
|
||||||
void
|
void
|
||||||
screen_free(struct screen *s)
|
screen_free(struct screen *s)
|
||||||
{
|
{
|
||||||
|
free(s->sel);
|
||||||
free(s->tabs);
|
free(s->tabs);
|
||||||
free(s->title);
|
free(s->title);
|
||||||
free(s->ccolour);
|
free(s->ccolour);
|
||||||
|
|
||||||
grid_destroy(s->grid);
|
grid_destroy(s->grid);
|
||||||
|
|
||||||
|
screen_free_titles(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset tabs to default, eight spaces apart. */
|
/* Reset tabs to default, eight spaces apart. */
|
||||||
@@ -110,6 +159,43 @@ screen_set_title(struct screen *s, const char *title)
|
|||||||
utf8_stravis(&s->title, title, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL);
|
utf8_stravis(&s->title, title, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Push the current title onto the stack. */
|
||||||
|
void
|
||||||
|
screen_push_title(struct screen *s)
|
||||||
|
{
|
||||||
|
struct screen_title_entry *title_entry;
|
||||||
|
|
||||||
|
if (s->titles == NULL) {
|
||||||
|
s->titles = xmalloc(sizeof *s->titles);
|
||||||
|
TAILQ_INIT(s->titles);
|
||||||
|
}
|
||||||
|
title_entry = xmalloc(sizeof *title_entry);
|
||||||
|
title_entry->text = xstrdup(s->title);
|
||||||
|
TAILQ_INSERT_HEAD(s->titles, title_entry, entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pop a title from the stack and set it as the screen title. If the stack is
|
||||||
|
* empty, do nothing.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
screen_pop_title(struct screen *s)
|
||||||
|
{
|
||||||
|
struct screen_title_entry *title_entry;
|
||||||
|
|
||||||
|
if (s->titles == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
title_entry = TAILQ_FIRST(s->titles);
|
||||||
|
if (title_entry != NULL) {
|
||||||
|
screen_set_title(s, title_entry->text);
|
||||||
|
|
||||||
|
TAILQ_REMOVE(s->titles, title_entry, entry);
|
||||||
|
free(title_entry->text);
|
||||||
|
free(title_entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Resize screen. */
|
/* Resize screen. */
|
||||||
void
|
void
|
||||||
screen_resize(struct screen *s, u_int sx, u_int sy, int reflow)
|
screen_resize(struct screen *s, u_int sx, u_int sy, int reflow)
|
||||||
@@ -128,7 +214,8 @@ screen_resize(struct screen *s, u_int sx, u_int sy, int reflow)
|
|||||||
* is simpler and more reliable so let's do that.
|
* is simpler and more reliable so let's do that.
|
||||||
*/
|
*/
|
||||||
screen_reset_tabs(s);
|
screen_reset_tabs(s);
|
||||||
}
|
} else
|
||||||
|
reflow = 0;
|
||||||
|
|
||||||
if (sy != screen_size_y(s))
|
if (sy != screen_size_y(s))
|
||||||
screen_resize_y(s, sy);
|
screen_resize_y(s, sy);
|
||||||
@@ -211,9 +298,8 @@ screen_resize_y(struct screen *s, u_int sy)
|
|||||||
s->cy -= needed;
|
s->cy -= needed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resize line arrays. */
|
/* Resize line array. */
|
||||||
gd->linedata = xreallocarray(gd->linedata, gd->hsize + sy,
|
grid_adjust_lines(gd, gd->hsize + sy);
|
||||||
sizeof *gd->linedata);
|
|
||||||
|
|
||||||
/* Size increasing. */
|
/* Size increasing. */
|
||||||
if (sy > oldy) {
|
if (sy > oldy) {
|
||||||
@@ -236,7 +322,7 @@ screen_resize_y(struct screen *s, u_int sy)
|
|||||||
|
|
||||||
/* Then fill the rest in with blanks. */
|
/* Then fill the rest in with blanks. */
|
||||||
for (i = gd->hsize + sy - needed; i < gd->hsize + sy; i++)
|
for (i = gd->hsize + sy - needed; i < gd->hsize + sy; i++)
|
||||||
memset(&gd->linedata[i], 0, sizeof gd->linedata[i]);
|
memset(grid_get_line(gd, i), 0, sizeof(struct grid_line));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the new size, and reset the scroll region. */
|
/* Set the new size, and reset the scroll region. */
|
||||||
@@ -248,51 +334,49 @@ screen_resize_y(struct screen *s, u_int sy)
|
|||||||
/* Set selection. */
|
/* Set selection. */
|
||||||
void
|
void
|
||||||
screen_set_selection(struct screen *s, u_int sx, u_int sy,
|
screen_set_selection(struct screen *s, u_int sx, u_int sy,
|
||||||
u_int ex, u_int ey, u_int rectflag, struct grid_cell *gc)
|
u_int ex, u_int ey, u_int rectangle, int modekeys, struct grid_cell *gc)
|
||||||
{
|
{
|
||||||
struct screen_sel *sel = &s->sel;
|
if (s->sel == NULL)
|
||||||
|
s->sel = xcalloc(1, sizeof *s->sel);
|
||||||
|
|
||||||
memcpy(&sel->cell, gc, sizeof sel->cell);
|
memcpy(&s->sel->cell, gc, sizeof s->sel->cell);
|
||||||
sel->flag = 1;
|
s->sel->hidden = 0;
|
||||||
sel->hidden = 0;
|
s->sel->rectangle = rectangle;
|
||||||
|
s->sel->modekeys = modekeys;
|
||||||
|
|
||||||
sel->rectflag = rectflag;
|
s->sel->sx = sx;
|
||||||
|
s->sel->sy = sy;
|
||||||
sel->sx = sx; sel->sy = sy;
|
s->sel->ex = ex;
|
||||||
sel->ex = ex; sel->ey = ey;
|
s->sel->ey = ey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear selection. */
|
/* Clear selection. */
|
||||||
void
|
void
|
||||||
screen_clear_selection(struct screen *s)
|
screen_clear_selection(struct screen *s)
|
||||||
{
|
{
|
||||||
struct screen_sel *sel = &s->sel;
|
free(s->sel);
|
||||||
|
s->sel = NULL;
|
||||||
sel->flag = 0;
|
|
||||||
sel->hidden = 0;
|
|
||||||
sel->lineflag = LINE_SEL_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hide selection. */
|
/* Hide selection. */
|
||||||
void
|
void
|
||||||
screen_hide_selection(struct screen *s)
|
screen_hide_selection(struct screen *s)
|
||||||
{
|
{
|
||||||
struct screen_sel *sel = &s->sel;
|
if (s->sel != NULL)
|
||||||
|
s->sel->hidden = 1;
|
||||||
sel->hidden = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if cell in selection. */
|
/* Check if cell in selection. */
|
||||||
int
|
int
|
||||||
screen_check_selection(struct screen *s, u_int px, u_int py)
|
screen_check_selection(struct screen *s, u_int px, u_int py)
|
||||||
{
|
{
|
||||||
struct screen_sel *sel = &s->sel;
|
struct screen_sel *sel = s->sel;
|
||||||
u_int xx;
|
u_int xx;
|
||||||
|
|
||||||
if (!sel->flag || sel->hidden)
|
if (sel == NULL || sel->hidden)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
if (sel->rectflag) {
|
if (sel->rectangle) {
|
||||||
if (sel->sy < sel->ey) {
|
if (sel->sy < sel->ey) {
|
||||||
/* start line < end line -- downward selection. */
|
/* start line < end line -- downward selection. */
|
||||||
if (py < sel->sy || py > sel->ey)
|
if (py < sel->sy || py > sel->ey)
|
||||||
@@ -385,10 +469,10 @@ void
|
|||||||
screen_select_cell(struct screen *s, struct grid_cell *dst,
|
screen_select_cell(struct screen *s, struct grid_cell *dst,
|
||||||
const struct grid_cell *src)
|
const struct grid_cell *src)
|
||||||
{
|
{
|
||||||
if (!s->sel.flag || s->sel.hidden)
|
if (s->sel == NULL || s->sel->hidden)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memcpy(dst, &s->sel.cell, sizeof *dst);
|
memcpy(dst, &s->sel->cell, sizeof *dst);
|
||||||
|
|
||||||
utf8_copy(&dst->data, &src->data);
|
utf8_copy(&dst->data, &src->data);
|
||||||
dst->attr = dst->attr & ~GRID_ATTR_CHARSET;
|
dst->attr = dst->attr & ~GRID_ATTR_CHARSET;
|
||||||
@@ -400,14 +484,5 @@ screen_select_cell(struct screen *s, struct grid_cell *dst,
|
|||||||
static void
|
static void
|
||||||
screen_reflow(struct screen *s, u_int new_x)
|
screen_reflow(struct screen *s, u_int new_x)
|
||||||
{
|
{
|
||||||
struct grid *old = s->grid;
|
grid_reflow(s->grid, new_x, &s->cy);
|
||||||
u_int change;
|
|
||||||
|
|
||||||
s->grid = grid_create(old->sx, old->sy, old->hlimit);
|
|
||||||
|
|
||||||
change = grid_reflow(s->grid, old, new_x);
|
|
||||||
if (change < s->cy)
|
|
||||||
s->cy -= change;
|
|
||||||
else
|
|
||||||
s->cy = 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
101
server-client.c
101
server-client.c
@@ -41,6 +41,8 @@ static void server_client_check_redraw(struct client *);
|
|||||||
static void server_client_set_title(struct client *);
|
static void server_client_set_title(struct client *);
|
||||||
static void server_client_reset_state(struct client *);
|
static void server_client_reset_state(struct client *);
|
||||||
static int server_client_assume_paste(struct session *);
|
static int server_client_assume_paste(struct session *);
|
||||||
|
static void server_client_clear_identify(struct client *,
|
||||||
|
struct window_pane *);
|
||||||
|
|
||||||
static void server_client_dispatch(struct imsg *, void *);
|
static void server_client_dispatch(struct imsg *, void *);
|
||||||
static void server_client_dispatch_command(struct client *, struct imsg *);
|
static void server_client_dispatch_command(struct client *, struct imsg *);
|
||||||
@@ -91,7 +93,7 @@ server_client_set_identify(struct client *c, u_int delay)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Clear identify mode on client. */
|
/* Clear identify mode on client. */
|
||||||
void
|
static void
|
||||||
server_client_clear_identify(struct client *c, struct window_pane *wp)
|
server_client_clear_identify(struct client *c, struct window_pane *wp)
|
||||||
{
|
{
|
||||||
if (~c->flags & CLIENT_IDENTIFY)
|
if (~c->flags & CLIENT_IDENTIFY)
|
||||||
@@ -159,7 +161,7 @@ server_client_is_default_key_table(struct client *c, struct key_table *table)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create a new client. */
|
/* Create a new client. */
|
||||||
void
|
struct client *
|
||||||
server_client_create(int fd)
|
server_client_create(int fd)
|
||||||
{
|
{
|
||||||
struct client *c;
|
struct client *c;
|
||||||
@@ -193,7 +195,7 @@ server_client_create(int fd)
|
|||||||
c->tty.sx = 80;
|
c->tty.sx = 80;
|
||||||
c->tty.sy = 24;
|
c->tty.sy = 24;
|
||||||
|
|
||||||
screen_init(&c->status, c->tty.sx, 1, 0);
|
screen_init(&c->status.status, c->tty.sx, 1, 0);
|
||||||
|
|
||||||
c->message_string = NULL;
|
c->message_string = NULL;
|
||||||
TAILQ_INIT(&c->message_log);
|
TAILQ_INIT(&c->message_log);
|
||||||
@@ -212,6 +214,7 @@ server_client_create(int fd)
|
|||||||
|
|
||||||
TAILQ_INSERT_TAIL(&clients, c, entry);
|
TAILQ_INSERT_TAIL(&clients, c, entry);
|
||||||
log_debug("new client %p", c);
|
log_debug("new client %p", c);
|
||||||
|
return (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open client terminal if needed. */
|
/* Open client terminal if needed. */
|
||||||
@@ -269,12 +272,12 @@ server_client_lost(struct client *c)
|
|||||||
if (c->stderr_data != c->stdout_data)
|
if (c->stderr_data != c->stdout_data)
|
||||||
evbuffer_free(c->stderr_data);
|
evbuffer_free(c->stderr_data);
|
||||||
|
|
||||||
if (event_initialized(&c->status_timer))
|
if (event_initialized(&c->status.timer))
|
||||||
evtimer_del(&c->status_timer);
|
evtimer_del(&c->status.timer);
|
||||||
screen_free(&c->status);
|
screen_free(&c->status.status);
|
||||||
if (c->old_status != NULL) {
|
if (c->status.old_status != NULL) {
|
||||||
screen_free(c->old_status);
|
screen_free(c->status.old_status);
|
||||||
free(c->old_status);
|
free(c->status.old_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(c->title);
|
free(c->title);
|
||||||
@@ -812,7 +815,7 @@ server_client_handle_key(struct client *c, key_code key)
|
|||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct key_table *table, *first;
|
struct key_table *table, *first;
|
||||||
struct key_binding bd_find, *bd;
|
struct key_binding *bd;
|
||||||
int xtimeout, flags;
|
int xtimeout, flags;
|
||||||
struct cmd_find_state fs;
|
struct cmd_find_state fs;
|
||||||
key_code key0;
|
key_code key0;
|
||||||
@@ -881,11 +884,11 @@ server_client_handle_key(struct client *c, key_code key)
|
|||||||
|
|
||||||
/* Forward mouse keys if disabled. */
|
/* Forward mouse keys if disabled. */
|
||||||
if (KEYC_IS_MOUSE(key) && !options_get_number(s->options, "mouse"))
|
if (KEYC_IS_MOUSE(key) && !options_get_number(s->options, "mouse"))
|
||||||
goto forward;
|
goto forward_key;
|
||||||
|
|
||||||
/* Treat everything as a regular key when pasting is detected. */
|
/* Treat everything as a regular key when pasting is detected. */
|
||||||
if (!KEYC_IS_MOUSE(key) && server_client_assume_paste(s))
|
if (!KEYC_IS_MOUSE(key) && server_client_assume_paste(s))
|
||||||
goto forward;
|
goto forward_key;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Work out the current key table. If the pane is in a mode, use
|
* Work out the current key table. If the pane is in a mode, use
|
||||||
@@ -900,6 +903,7 @@ server_client_handle_key(struct client *c, key_code key)
|
|||||||
table = c->keytable;
|
table = c->keytable;
|
||||||
first = table;
|
first = table;
|
||||||
|
|
||||||
|
table_changed:
|
||||||
/*
|
/*
|
||||||
* The prefix always takes precedence and forces a switch to the prefix
|
* The prefix always takes precedence and forces a switch to the prefix
|
||||||
* table, unless we are already there.
|
* table, unless we are already there.
|
||||||
@@ -914,7 +918,6 @@ server_client_handle_key(struct client *c, key_code key)
|
|||||||
}
|
}
|
||||||
flags = c->flags;
|
flags = c->flags;
|
||||||
|
|
||||||
retry:
|
|
||||||
/* Log key table. */
|
/* Log key table. */
|
||||||
if (wp == NULL)
|
if (wp == NULL)
|
||||||
log_debug("key table %s (no pane)", table->name);
|
log_debug("key table %s (no pane)", table->name);
|
||||||
@@ -923,9 +926,9 @@ retry:
|
|||||||
if (c->flags & CLIENT_REPEAT)
|
if (c->flags & CLIENT_REPEAT)
|
||||||
log_debug("currently repeating");
|
log_debug("currently repeating");
|
||||||
|
|
||||||
|
try_again:
|
||||||
/* Try to see if there is a key binding in the current table. */
|
/* Try to see if there is a key binding in the current table. */
|
||||||
bd_find.key = key0;
|
bd = key_bindings_get(table, key0);
|
||||||
bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find);
|
|
||||||
if (bd != NULL) {
|
if (bd != NULL) {
|
||||||
/*
|
/*
|
||||||
* Key was matched in this table. If currently repeating but a
|
* Key was matched in this table. If currently repeating but a
|
||||||
@@ -938,7 +941,7 @@ retry:
|
|||||||
c->flags &= ~CLIENT_REPEAT;
|
c->flags &= ~CLIENT_REPEAT;
|
||||||
server_status_client(c);
|
server_status_client(c);
|
||||||
table = c->keytable;
|
table = c->keytable;
|
||||||
goto retry;
|
goto table_changed;
|
||||||
}
|
}
|
||||||
log_debug("found in key table %s", table->name);
|
log_debug("found in key table %s", table->name);
|
||||||
|
|
||||||
@@ -972,6 +975,14 @@ retry:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* No match, try the ANY key.
|
||||||
|
*/
|
||||||
|
if (key0 != KEYC_ANY) {
|
||||||
|
key0 = KEYC_ANY;
|
||||||
|
goto try_again;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* No match in this table. If not in the root table or if repeating,
|
* No match in this table. If not in the root table or if repeating,
|
||||||
* switch the client back to the root table and try again.
|
* switch the client back to the root table and try again.
|
||||||
@@ -983,7 +994,7 @@ retry:
|
|||||||
c->flags &= ~CLIENT_REPEAT;
|
c->flags &= ~CLIENT_REPEAT;
|
||||||
server_status_client(c);
|
server_status_client(c);
|
||||||
table = c->keytable;
|
table = c->keytable;
|
||||||
goto retry;
|
goto table_changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -996,7 +1007,7 @@ retry:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
forward:
|
forward_key:
|
||||||
if (c->flags & CLIENT_READONLY)
|
if (c->flags & CLIENT_READONLY)
|
||||||
return;
|
return;
|
||||||
if (wp != NULL)
|
if (wp != NULL)
|
||||||
@@ -1067,7 +1078,7 @@ server_client_resize_force(struct window_pane *wp)
|
|||||||
memset(&ws, 0, sizeof ws);
|
memset(&ws, 0, sizeof ws);
|
||||||
ws.ws_col = wp->sx;
|
ws.ws_col = wp->sx;
|
||||||
ws.ws_row = wp->sy - 1;
|
ws.ws_row = wp->sy - 1;
|
||||||
if (ioctl(wp->fd, TIOCSWINSZ, &ws) == -1)
|
if (wp->fd != -1 && ioctl(wp->fd, TIOCSWINSZ, &ws) == -1)
|
||||||
#ifdef __sun
|
#ifdef __sun
|
||||||
if (errno != EINVAL && errno != ENXIO)
|
if (errno != EINVAL && errno != ENXIO)
|
||||||
#endif
|
#endif
|
||||||
@@ -1096,7 +1107,7 @@ server_client_resize_event(__unused int fd, __unused short events, void *data)
|
|||||||
memset(&ws, 0, sizeof ws);
|
memset(&ws, 0, sizeof ws);
|
||||||
ws.ws_col = wp->sx;
|
ws.ws_col = wp->sx;
|
||||||
ws.ws_row = wp->sy;
|
ws.ws_row = wp->sy;
|
||||||
if (ioctl(wp->fd, TIOCSWINSZ, &ws) == -1)
|
if (wp->fd != -1 && ioctl(wp->fd, TIOCSWINSZ, &ws) == -1)
|
||||||
#ifdef __sun
|
#ifdef __sun
|
||||||
/*
|
/*
|
||||||
* Some versions of Solaris apparently can return an error when
|
* Some versions of Solaris apparently can return an error when
|
||||||
@@ -1157,10 +1168,6 @@ server_client_check_focus(struct window_pane *wp)
|
|||||||
push = wp->flags & PANE_FOCUSPUSH;
|
push = wp->flags & PANE_FOCUSPUSH;
|
||||||
wp->flags &= ~PANE_FOCUSPUSH;
|
wp->flags &= ~PANE_FOCUSPUSH;
|
||||||
|
|
||||||
/* If we don't care about focus, forget it. */
|
|
||||||
if (!(wp->base.mode & MODE_FOCUSON))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* If we're not the active pane in our window, we're not focused. */
|
/* If we're not the active pane in our window, we're not focused. */
|
||||||
if (wp->window->active != wp)
|
if (wp->window->active != wp)
|
||||||
goto not_focused;
|
goto not_focused;
|
||||||
@@ -1184,14 +1191,20 @@ server_client_check_focus(struct window_pane *wp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
not_focused:
|
not_focused:
|
||||||
if (push || (wp->flags & PANE_FOCUSED))
|
if (push || (wp->flags & PANE_FOCUSED)) {
|
||||||
bufferevent_write(wp->event, "\033[O", 3);
|
if (wp->base.mode & MODE_FOCUSON)
|
||||||
|
bufferevent_write(wp->event, "\033[O", 3);
|
||||||
|
notify_pane("pane-focus-out", wp);
|
||||||
|
}
|
||||||
wp->flags &= ~PANE_FOCUSED;
|
wp->flags &= ~PANE_FOCUSED;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
focused:
|
focused:
|
||||||
if (push || !(wp->flags & PANE_FOCUSED))
|
if (push || !(wp->flags & PANE_FOCUSED)) {
|
||||||
bufferevent_write(wp->event, "\033[I", 3);
|
if (wp->base.mode & MODE_FOCUSON)
|
||||||
|
bufferevent_write(wp->event, "\033[I", 3);
|
||||||
|
notify_pane("pane-focus-in", wp);
|
||||||
|
}
|
||||||
wp->flags |= PANE_FOCUSED;
|
wp->flags |= PANE_FOCUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1211,7 +1224,7 @@ server_client_reset_state(struct client *c)
|
|||||||
struct window_pane *wp = w->active, *loop;
|
struct window_pane *wp = w->active, *loop;
|
||||||
struct screen *s = wp->screen;
|
struct screen *s = wp->screen;
|
||||||
struct options *oo = c->session->options;
|
struct options *oo = c->session->options;
|
||||||
int status, mode, o;
|
int lines, mode;
|
||||||
|
|
||||||
if (c->flags & (CLIENT_CONTROL|CLIENT_SUSPENDED))
|
if (c->flags & (CLIENT_CONTROL|CLIENT_SUSPENDED))
|
||||||
return;
|
return;
|
||||||
@@ -1219,13 +1232,14 @@ server_client_reset_state(struct client *c)
|
|||||||
tty_region_off(&c->tty);
|
tty_region_off(&c->tty);
|
||||||
tty_margin_off(&c->tty);
|
tty_margin_off(&c->tty);
|
||||||
|
|
||||||
status = options_get_number(oo, "status");
|
if (status_at_line(c) != 0)
|
||||||
if (!window_pane_visible(wp) || wp->yoff + s->cy >= c->tty.sy - status)
|
lines = 0;
|
||||||
|
else
|
||||||
|
lines = status_line_size(c->session);
|
||||||
|
if (!window_pane_visible(wp) || wp->yoff + s->cy >= c->tty.sy - lines)
|
||||||
tty_cursor(&c->tty, 0, 0);
|
tty_cursor(&c->tty, 0, 0);
|
||||||
else {
|
else
|
||||||
o = status && options_get_number(oo, "status-position") == 0;
|
tty_cursor(&c->tty, wp->xoff + s->cx, lines + wp->yoff + s->cy);
|
||||||
tty_cursor(&c->tty, wp->xoff + s->cx, o + wp->yoff + s->cy);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set mouse mode if requested. To support dragging, always use button
|
* Set mouse mode if requested. To support dragging, always use button
|
||||||
@@ -1287,6 +1301,8 @@ server_client_check_exit(struct client *c)
|
|||||||
if (EVBUFFER_LENGTH(c->stderr_data) != 0)
|
if (EVBUFFER_LENGTH(c->stderr_data) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (c->flags & CLIENT_ATTACHED)
|
||||||
|
notify_client("client-detached", c);
|
||||||
proc_send(c->peer, MSG_EXIT, -1, &c->retval, sizeof c->retval);
|
proc_send(c->peer, MSG_EXIT, -1, &c->retval, sizeof c->retval);
|
||||||
c->flags &= ~CLIENT_EXIT;
|
c->flags &= ~CLIENT_EXIT;
|
||||||
}
|
}
|
||||||
@@ -1559,6 +1575,9 @@ server_client_dispatch_command(struct client *c, struct imsg *imsg)
|
|||||||
int argc;
|
int argc;
|
||||||
char **argv, *cause;
|
char **argv, *cause;
|
||||||
|
|
||||||
|
if (c->flags & CLIENT_EXIT)
|
||||||
|
return;
|
||||||
|
|
||||||
if (imsg->hdr.len - IMSG_HEADER_SIZE < sizeof data)
|
if (imsg->hdr.len - IMSG_HEADER_SIZE < sizeof data)
|
||||||
fatalx("bad MSG_COMMAND size");
|
fatalx("bad MSG_COMMAND size");
|
||||||
memcpy(&data, imsg->data, sizeof data);
|
memcpy(&data, imsg->data, sizeof data);
|
||||||
@@ -1854,15 +1873,19 @@ server_client_add_message(struct client *c, const char *fmt, ...)
|
|||||||
|
|
||||||
/* Get client working directory. */
|
/* Get client working directory. */
|
||||||
const char *
|
const char *
|
||||||
server_client_get_cwd(struct client *c)
|
server_client_get_cwd(struct client *c, struct session *s)
|
||||||
{
|
{
|
||||||
struct session *s;
|
const char *home;
|
||||||
|
|
||||||
if (c != NULL && c->session == NULL && c->cwd != NULL)
|
if (c != NULL && c->session == NULL && c->cwd != NULL)
|
||||||
return (c->cwd);
|
return (c->cwd);
|
||||||
|
if (s != NULL && s->cwd != NULL)
|
||||||
|
return (s->cwd);
|
||||||
if (c != NULL && (s = c->session) != NULL && s->cwd != NULL)
|
if (c != NULL && (s = c->session) != NULL && s->cwd != NULL)
|
||||||
return (s->cwd);
|
return (s->cwd);
|
||||||
return (".");
|
if ((home = find_home()) != NULL)
|
||||||
|
return (home);
|
||||||
|
return ("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resolve an absolute path or relative to client working directory. */
|
/* Resolve an absolute path or relative to client working directory. */
|
||||||
@@ -1874,7 +1897,7 @@ server_client_get_path(struct client *c, const char *file)
|
|||||||
if (*file == '/')
|
if (*file == '/')
|
||||||
path = xstrdup(file);
|
path = xstrdup(file);
|
||||||
else
|
else
|
||||||
xasprintf(&path, "%s/%s", server_client_get_cwd(c), file);
|
xasprintf(&path, "%s/%s", server_client_get_cwd(c, NULL), file);
|
||||||
if (realpath(path, resolved) == NULL)
|
if (realpath(path, resolved) == NULL)
|
||||||
return (path);
|
return (path);
|
||||||
free(path);
|
free(path);
|
||||||
|
|||||||
50
server-fn.c
50
server-fn.c
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -174,6 +175,22 @@ server_lock_client(struct client *c)
|
|||||||
proc_send(c->peer, MSG_LOCK, -1, cmd, strlen(cmd) + 1);
|
proc_send(c->peer, MSG_LOCK, -1, cmd, strlen(cmd) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
server_kill_pane(struct window_pane *wp)
|
||||||
|
{
|
||||||
|
struct window *w = wp->window;
|
||||||
|
|
||||||
|
if (window_count_panes(w) == 1) {
|
||||||
|
server_kill_window(w);
|
||||||
|
recalculate_sizes();
|
||||||
|
} else {
|
||||||
|
server_unzoom_window(w);
|
||||||
|
layout_close_pane(wp);
|
||||||
|
window_remove_pane(w, wp);
|
||||||
|
server_redraw_window(w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
server_kill_window(struct window *w)
|
server_kill_window(struct window *w)
|
||||||
{
|
{
|
||||||
@@ -276,11 +293,11 @@ void
|
|||||||
server_destroy_pane(struct window_pane *wp, int notify)
|
server_destroy_pane(struct window_pane *wp, int notify)
|
||||||
{
|
{
|
||||||
struct window *w = wp->window;
|
struct window *w = wp->window;
|
||||||
int old_fd;
|
|
||||||
struct screen_write_ctx ctx;
|
struct screen_write_ctx ctx;
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
|
time_t t;
|
||||||
|
char tim[26];
|
||||||
|
|
||||||
old_fd = wp->fd;
|
|
||||||
if (wp->fd != -1) {
|
if (wp->fd != -1) {
|
||||||
#ifdef HAVE_UTEMPTER
|
#ifdef HAVE_UTEMPTER
|
||||||
utempter_remove_record(wp->fd);
|
utempter_remove_record(wp->fd);
|
||||||
@@ -291,9 +308,13 @@ server_destroy_pane(struct window_pane *wp, int notify)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options_get_number(w->options, "remain-on-exit")) {
|
if (options_get_number(w->options, "remain-on-exit")) {
|
||||||
if (old_fd == -1)
|
if (~wp->flags & PANE_STATUSREADY)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (wp->flags & PANE_STATUSDRAWN)
|
||||||
|
return;
|
||||||
|
wp->flags |= PANE_STATUSDRAWN;
|
||||||
|
|
||||||
if (notify)
|
if (notify)
|
||||||
notify_pane("pane-died", wp);
|
notify_pane("pane-died", wp);
|
||||||
|
|
||||||
@@ -302,11 +323,24 @@ server_destroy_pane(struct window_pane *wp, int notify)
|
|||||||
screen_write_cursormove(&ctx, 0, screen_size_y(ctx.s) - 1);
|
screen_write_cursormove(&ctx, 0, screen_size_y(ctx.s) - 1);
|
||||||
screen_write_linefeed(&ctx, 1, 8);
|
screen_write_linefeed(&ctx, 1, 8);
|
||||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||||
gc.attr |= GRID_ATTR_BRIGHT;
|
|
||||||
screen_write_puts(&ctx, &gc, "Pane is dead");
|
time(&t);
|
||||||
|
ctime_r(&t, tim);
|
||||||
|
|
||||||
|
if (WIFEXITED(wp->status)) {
|
||||||
|
screen_write_nputs(&ctx, -1, &gc,
|
||||||
|
"Pane is dead (status %d, %s)",
|
||||||
|
WEXITSTATUS(wp->status),
|
||||||
|
tim);
|
||||||
|
} else if (WIFSIGNALED(wp->status)) {
|
||||||
|
screen_write_nputs(&ctx, -1, &gc,
|
||||||
|
"Pane is dead (signal %d, %s)",
|
||||||
|
WTERMSIG(wp->status),
|
||||||
|
tim);
|
||||||
|
}
|
||||||
|
|
||||||
screen_write_stop(&ctx);
|
screen_write_stop(&ctx);
|
||||||
wp->flags |= PANE_REDRAW;
|
wp->flags |= PANE_REDRAW;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,8 +472,6 @@ server_set_stdin_callback(struct client *c, void (*cb)(struct client *, int,
|
|||||||
void
|
void
|
||||||
server_unzoom_window(struct window *w)
|
server_unzoom_window(struct window *w)
|
||||||
{
|
{
|
||||||
if (window_unzoom(w) == 0) {
|
if (window_unzoom(w) == 0)
|
||||||
server_redraw_window(w);
|
server_redraw_window(w);
|
||||||
server_status_window(w);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
72
server.c
72
server.c
@@ -49,7 +49,6 @@ static struct event server_ev_accept;
|
|||||||
|
|
||||||
struct cmd_find_state marked_pane;
|
struct cmd_find_state marked_pane;
|
||||||
|
|
||||||
static int server_create_socket(void);
|
|
||||||
static int server_loop(void);
|
static int server_loop(void);
|
||||||
static void server_send_exit(void);
|
static void server_send_exit(void);
|
||||||
static void server_accept(int, short, void *);
|
static void server_accept(int, short, void *);
|
||||||
@@ -98,39 +97,62 @@ server_check_marked(void)
|
|||||||
|
|
||||||
/* Create server socket. */
|
/* Create server socket. */
|
||||||
static int
|
static int
|
||||||
server_create_socket(void)
|
server_create_socket(char **cause)
|
||||||
{
|
{
|
||||||
struct sockaddr_un sa;
|
struct sockaddr_un sa;
|
||||||
size_t size;
|
size_t size;
|
||||||
mode_t mask;
|
mode_t mask;
|
||||||
int fd;
|
int fd, saved_errno;
|
||||||
|
|
||||||
memset(&sa, 0, sizeof sa);
|
memset(&sa, 0, sizeof sa);
|
||||||
sa.sun_family = AF_UNIX;
|
sa.sun_family = AF_UNIX;
|
||||||
size = strlcpy(sa.sun_path, socket_path, sizeof sa.sun_path);
|
size = strlcpy(sa.sun_path, socket_path, sizeof sa.sun_path);
|
||||||
if (size >= sizeof sa.sun_path) {
|
if (size >= sizeof sa.sun_path) {
|
||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
return (-1);
|
goto fail;
|
||||||
}
|
}
|
||||||
unlink(sa.sun_path);
|
unlink(sa.sun_path);
|
||||||
|
|
||||||
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||||
return (-1);
|
goto fail;
|
||||||
|
|
||||||
mask = umask(S_IXUSR|S_IXGRP|S_IRWXO);
|
mask = umask(S_IXUSR|S_IXGRP|S_IRWXO);
|
||||||
if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) == -1) {
|
if (bind(fd, (struct sockaddr *)&sa, sizeof sa) == -1) {
|
||||||
|
saved_errno = errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
return (-1);
|
errno = saved_errno;
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
umask(mask);
|
umask(mask);
|
||||||
|
|
||||||
if (listen(fd, 128) == -1) {
|
if (listen(fd, 128) == -1) {
|
||||||
|
saved_errno = errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
return (-1);
|
errno = saved_errno;
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
setblocking(fd, 0);
|
setblocking(fd, 0);
|
||||||
|
|
||||||
return (fd);
|
return (fd);
|
||||||
|
|
||||||
|
fail:
|
||||||
|
if (cause != NULL) {
|
||||||
|
xasprintf(cause, "error creating %s (%s)", socket_path,
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Server error callback. */
|
||||||
|
static enum cmd_retval
|
||||||
|
server_start_error(struct cmdq_item *item, void *data)
|
||||||
|
{
|
||||||
|
char *error = data;
|
||||||
|
|
||||||
|
cmdq_error(item, "%s", error);
|
||||||
|
free(error);
|
||||||
|
|
||||||
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fork new server. */
|
/* Fork new server. */
|
||||||
@@ -141,6 +163,8 @@ server_start(struct tmuxproc *client, struct event_base *base, int lockfd,
|
|||||||
int pair[2];
|
int pair[2];
|
||||||
struct job *job;
|
struct job *job;
|
||||||
sigset_t set, oldset;
|
sigset_t set, oldset;
|
||||||
|
struct client *c;
|
||||||
|
char *cause = NULL;
|
||||||
|
|
||||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
|
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
|
||||||
fatal("socketpair failed");
|
fatal("socketpair failed");
|
||||||
@@ -177,16 +201,14 @@ server_start(struct tmuxproc *client, struct event_base *base, int lockfd,
|
|||||||
RB_INIT(&all_window_panes);
|
RB_INIT(&all_window_panes);
|
||||||
TAILQ_INIT(&clients);
|
TAILQ_INIT(&clients);
|
||||||
RB_INIT(&sessions);
|
RB_INIT(&sessions);
|
||||||
RB_INIT(&session_groups);
|
|
||||||
key_bindings_init();
|
key_bindings_init();
|
||||||
|
|
||||||
gettimeofday(&start_time, NULL);
|
gettimeofday(&start_time, NULL);
|
||||||
|
|
||||||
server_fd = server_create_socket();
|
server_fd = server_create_socket(&cause);
|
||||||
if (server_fd == -1)
|
if (server_fd != -1)
|
||||||
fatal("couldn't create socket");
|
server_update_socket();
|
||||||
server_update_socket();
|
c = server_client_create(pair[1]);
|
||||||
server_client_create(pair[1]);
|
|
||||||
|
|
||||||
if (lockfd >= 0) {
|
if (lockfd >= 0) {
|
||||||
unlink(lockfile);
|
unlink(lockfile);
|
||||||
@@ -194,6 +216,11 @@ server_start(struct tmuxproc *client, struct event_base *base, int lockfd,
|
|||||||
close(lockfd);
|
close(lockfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cause != NULL) {
|
||||||
|
cmdq_append(c, cmdq_get_callback(server_start_error, cause));
|
||||||
|
c->flags |= CLIENT_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
start_cfg();
|
start_cfg();
|
||||||
|
|
||||||
server_add_accept(0);
|
server_add_accept(0);
|
||||||
@@ -215,6 +242,7 @@ server_loop(void)
|
|||||||
{
|
{
|
||||||
struct client *c;
|
struct client *c;
|
||||||
u_int items;
|
u_int items;
|
||||||
|
struct job *job;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
items = cmdq_next(NULL);
|
items = cmdq_next(NULL);
|
||||||
@@ -226,6 +254,9 @@ server_loop(void)
|
|||||||
|
|
||||||
server_client_loop();
|
server_client_loop();
|
||||||
|
|
||||||
|
if (!options_get_number(global_options, "exit-empty") && !server_exit)
|
||||||
|
return (0);
|
||||||
|
|
||||||
if (!options_get_number(global_options, "exit-unattached")) {
|
if (!options_get_number(global_options, "exit-unattached")) {
|
||||||
if (!RB_EMPTY(&sessions))
|
if (!RB_EMPTY(&sessions))
|
||||||
return (0);
|
return (0);
|
||||||
@@ -244,6 +275,11 @@ server_loop(void)
|
|||||||
if (!TAILQ_EMPTY(&clients))
|
if (!TAILQ_EMPTY(&clients))
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
|
LIST_FOREACH(job, &all_jobs, entry) {
|
||||||
|
if ((~job->flags & JOB_NOWAIT) && job->state == JOB_RUNNING)
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,8 +295,11 @@ server_send_exit(void)
|
|||||||
TAILQ_FOREACH_SAFE(c, &clients, entry, c1) {
|
TAILQ_FOREACH_SAFE(c, &clients, entry, c1) {
|
||||||
if (c->flags & CLIENT_SUSPENDED)
|
if (c->flags & CLIENT_SUSPENDED)
|
||||||
server_client_lost(c);
|
server_client_lost(c);
|
||||||
else
|
else {
|
||||||
|
if (c->flags & CLIENT_ATTACHED)
|
||||||
|
notify_client("client-detached", c);
|
||||||
proc_send(c->peer, MSG_SHUTDOWN, -1, NULL, 0);
|
proc_send(c->peer, MSG_SHUTDOWN, -1, NULL, 0);
|
||||||
|
}
|
||||||
c->session = NULL;
|
c->session = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,7 +413,7 @@ server_signal(int sig)
|
|||||||
break;
|
break;
|
||||||
case SIGUSR1:
|
case SIGUSR1:
|
||||||
event_del(&server_ev_accept);
|
event_del(&server_ev_accept);
|
||||||
fd = server_create_socket();
|
fd = server_create_socket(NULL);
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
close(server_fd);
|
close(server_fd);
|
||||||
server_fd = fd;
|
server_fd = fd;
|
||||||
@@ -423,6 +462,7 @@ server_child_exited(pid_t pid, int status)
|
|||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
if (wp->pid == pid) {
|
if (wp->pid == pid) {
|
||||||
wp->status = status;
|
wp->status = status;
|
||||||
|
wp->flags |= PANE_STATUSREADY;
|
||||||
|
|
||||||
log_debug("%%%u exited", wp->id);
|
log_debug("%%%u exited", wp->id);
|
||||||
wp->flags |= PANE_EXITED;
|
wp->flags |= PANE_EXITED;
|
||||||
|
|||||||
23
session.c
23
session.c
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
struct sessions sessions;
|
struct sessions sessions;
|
||||||
static u_int next_session_id;
|
static u_int next_session_id;
|
||||||
struct session_groups session_groups;
|
struct session_groups session_groups = RB_INITIALIZER(&session_groups);
|
||||||
|
|
||||||
static void session_free(int, short, void *);
|
static void session_free(int, short, void *);
|
||||||
|
|
||||||
@@ -38,27 +38,21 @@ static struct winlink *session_next_alert(struct winlink *);
|
|||||||
static struct winlink *session_previous_alert(struct winlink *);
|
static struct winlink *session_previous_alert(struct winlink *);
|
||||||
|
|
||||||
static void session_group_remove(struct session *);
|
static void session_group_remove(struct session *);
|
||||||
static u_int session_group_count(struct session_group *);
|
|
||||||
static void session_group_synchronize1(struct session *, struct session *);
|
static void session_group_synchronize1(struct session *, struct session *);
|
||||||
|
|
||||||
static u_int session_group_count(struct session_group *);
|
|
||||||
static void session_group_synchronize1(struct session *, struct session *);
|
|
||||||
|
|
||||||
RB_GENERATE(sessions, session, entry, session_cmp);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
session_cmp(struct session *s1, struct session *s2)
|
session_cmp(struct session *s1, struct session *s2)
|
||||||
{
|
{
|
||||||
return (strcmp(s1->name, s2->name));
|
return (strcmp(s1->name, s2->name));
|
||||||
}
|
}
|
||||||
|
RB_GENERATE(sessions, session, entry, session_cmp);
|
||||||
|
|
||||||
RB_GENERATE(session_groups, session_group, entry, session_group_cmp);
|
static int
|
||||||
|
|
||||||
int
|
|
||||||
session_group_cmp(struct session_group *s1, struct session_group *s2)
|
session_group_cmp(struct session_group *s1, struct session_group *s2)
|
||||||
{
|
{
|
||||||
return (strcmp(s1->name, s2->name));
|
return (strcmp(s1->name, s2->name));
|
||||||
}
|
}
|
||||||
|
RB_GENERATE_STATIC(session_groups, session_group, entry, session_group_cmp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find if session is still alive. This is true if it is still on the global
|
* Find if session is still alive. This is true if it is still on the global
|
||||||
@@ -294,9 +288,10 @@ session_update_activity(struct session *s, struct timeval *from)
|
|||||||
else
|
else
|
||||||
memcpy(&s->activity_time, from, sizeof s->activity_time);
|
memcpy(&s->activity_time, from, sizeof s->activity_time);
|
||||||
|
|
||||||
log_debug("session %s activity %lld.%06d (last %lld.%06d)", s->name,
|
log_debug("session $%u %s activity %lld.%06d (last %lld.%06d)", s->id,
|
||||||
(long long)s->activity_time.tv_sec, (int)s->activity_time.tv_usec,
|
s->name, (long long)s->activity_time.tv_sec,
|
||||||
(long long)last->tv_sec, (int)last->tv_usec);
|
(int)s->activity_time.tv_usec, (long long)last->tv_sec,
|
||||||
|
(int)last->tv_usec);
|
||||||
|
|
||||||
if (evtimer_initialized(&s->lock_timer))
|
if (evtimer_initialized(&s->lock_timer))
|
||||||
evtimer_del(&s->lock_timer);
|
evtimer_del(&s->lock_timer);
|
||||||
@@ -623,7 +618,7 @@ session_group_remove(struct session *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Count number of sessions in session group. */
|
/* Count number of sessions in session group. */
|
||||||
static u_int
|
u_int
|
||||||
session_group_count(struct session_group *sg)
|
session_group_count(struct session_group *sg)
|
||||||
{
|
{
|
||||||
struct session *s;
|
struct session *s;
|
||||||
|
|||||||
127
status.c
127
status.c
@@ -151,7 +151,7 @@ status_timer_callback(__unused int fd, __unused short events, void *arg)
|
|||||||
struct session *s = c->session;
|
struct session *s = c->session;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
evtimer_del(&c->status_timer);
|
evtimer_del(&c->status.timer);
|
||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return;
|
return;
|
||||||
@@ -163,7 +163,7 @@ status_timer_callback(__unused int fd, __unused short events, void *arg)
|
|||||||
tv.tv_sec = options_get_number(s->options, "status-interval");
|
tv.tv_sec = options_get_number(s->options, "status-interval");
|
||||||
|
|
||||||
if (tv.tv_sec != 0)
|
if (tv.tv_sec != 0)
|
||||||
evtimer_add(&c->status_timer, &tv);
|
evtimer_add(&c->status.timer, &tv);
|
||||||
log_debug("client %p, status interval %d", c, (int)tv.tv_sec);
|
log_debug("client %p, status interval %d", c, (int)tv.tv_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,10 +173,10 @@ status_timer_start(struct client *c)
|
|||||||
{
|
{
|
||||||
struct session *s = c->session;
|
struct session *s = c->session;
|
||||||
|
|
||||||
if (event_initialized(&c->status_timer))
|
if (event_initialized(&c->status.timer))
|
||||||
evtimer_del(&c->status_timer);
|
evtimer_del(&c->status.timer);
|
||||||
else
|
else
|
||||||
evtimer_set(&c->status_timer, status_timer_callback, c);
|
evtimer_set(&c->status.timer, status_timer_callback, c);
|
||||||
|
|
||||||
if (s != NULL && options_get_number(s->options, "status"))
|
if (s != NULL && options_get_number(s->options, "status"))
|
||||||
status_timer_callback(-1, 0, c);
|
status_timer_callback(-1, 0, c);
|
||||||
@@ -210,9 +210,24 @@ status_at_line(struct client *c)
|
|||||||
{
|
{
|
||||||
struct session *s = c->session;
|
struct session *s = c->session;
|
||||||
|
|
||||||
|
if (c->flags & CLIENT_STATUSOFF)
|
||||||
|
return (-1);
|
||||||
if (s->statusat != 1)
|
if (s->statusat != 1)
|
||||||
return (s->statusat);
|
return (s->statusat);
|
||||||
return (c->tty.sy - 1);
|
return (c->tty.sy - status_line_size(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get size of status line for session. 0 means off. Note that status line may
|
||||||
|
* be forced off for an individual client if it is too small (the
|
||||||
|
* CLIENT_STATUSOFF flag is set for this).
|
||||||
|
*/
|
||||||
|
u_int
|
||||||
|
status_line_size(struct session *s)
|
||||||
|
{
|
||||||
|
if (s->statusat == -1)
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Retrieve options for left string. */
|
/* Retrieve options for left string. */
|
||||||
@@ -296,20 +311,21 @@ status_redraw(struct client *c)
|
|||||||
time_t t;
|
time_t t;
|
||||||
char *left, *right;
|
char *left, *right;
|
||||||
const char *sep;
|
const char *sep;
|
||||||
u_int offset, needed;
|
u_int offset, needed, lines;
|
||||||
u_int wlstart, wlwidth, wlavailable, wloffset, wlsize;
|
u_int wlstart, wlwidth, wlavailable, wloffset, wlsize;
|
||||||
size_t llen, rlen, seplen;
|
size_t llen, rlen, seplen;
|
||||||
int larrow, rarrow;
|
int larrow, rarrow;
|
||||||
|
|
||||||
/* Delete the saved status line, if any. */
|
/* Delete the saved status line, if any. */
|
||||||
if (c->old_status != NULL) {
|
if (c->status.old_status != NULL) {
|
||||||
screen_free(c->old_status);
|
screen_free(c->status.old_status);
|
||||||
free(c->old_status);
|
free(c->status.old_status);
|
||||||
c->old_status = NULL;
|
c->status.old_status = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No status line? */
|
/* No status line? */
|
||||||
if (c->tty.sy == 0 || !options_get_number(s->options, "status"))
|
lines = status_line_size(s);
|
||||||
|
if (c->tty.sy == 0 || lines == 0)
|
||||||
return (1);
|
return (1);
|
||||||
left = right = NULL;
|
left = right = NULL;
|
||||||
larrow = rarrow = 0;
|
larrow = rarrow = 0;
|
||||||
@@ -321,15 +337,15 @@ status_redraw(struct client *c)
|
|||||||
style_apply(&stdgc, s->options, "status-style");
|
style_apply(&stdgc, s->options, "status-style");
|
||||||
|
|
||||||
/* Create the target screen. */
|
/* Create the target screen. */
|
||||||
memcpy(&old_status, &c->status, sizeof old_status);
|
memcpy(&old_status, &c->status.status, sizeof old_status);
|
||||||
screen_init(&c->status, c->tty.sx, 1, 0);
|
screen_init(&c->status.status, c->tty.sx, lines, 0);
|
||||||
screen_write_start(&ctx, NULL, &c->status);
|
screen_write_start(&ctx, NULL, &c->status.status);
|
||||||
for (offset = 0; offset < c->tty.sx; offset++)
|
for (offset = 0; offset < lines * c->tty.sx; offset++)
|
||||||
screen_write_putc(&ctx, &stdgc, ' ');
|
screen_write_putc(&ctx, &stdgc, ' ');
|
||||||
screen_write_stop(&ctx);
|
screen_write_stop(&ctx);
|
||||||
|
|
||||||
/* If the height is one line, blank status line. */
|
/* If the height is too small, blank status line. */
|
||||||
if (c->tty.sy <= 1)
|
if (c->tty.sy < lines)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* Work out left and right strings. */
|
/* Work out left and right strings. */
|
||||||
@@ -446,7 +462,7 @@ status_redraw(struct client *c)
|
|||||||
|
|
||||||
draw:
|
draw:
|
||||||
/* Begin drawing. */
|
/* Begin drawing. */
|
||||||
screen_write_start(&ctx, NULL, &c->status);
|
screen_write_start(&ctx, NULL, &c->status.status);
|
||||||
|
|
||||||
/* Draw the left string and arrow. */
|
/* Draw the left string and arrow. */
|
||||||
screen_write_cursormove(&ctx, 0, 0);
|
screen_write_cursormove(&ctx, 0, 0);
|
||||||
@@ -492,8 +508,7 @@ draw:
|
|||||||
/* Copy the window list. */
|
/* Copy the window list. */
|
||||||
c->wlmouse = -wloffset + wlstart;
|
c->wlmouse = -wloffset + wlstart;
|
||||||
screen_write_cursormove(&ctx, wloffset, 0);
|
screen_write_cursormove(&ctx, wloffset, 0);
|
||||||
screen_write_copy(&ctx, &window_list, wlstart, 0, wlwidth, 1, NULL,
|
screen_write_fast_copy(&ctx, &window_list, wlstart, 0, wlwidth, 1);
|
||||||
NULL);
|
|
||||||
screen_free(&window_list);
|
screen_free(&window_list);
|
||||||
|
|
||||||
screen_write_stop(&ctx);
|
screen_write_stop(&ctx);
|
||||||
@@ -502,7 +517,7 @@ out:
|
|||||||
free(left);
|
free(left);
|
||||||
free(right);
|
free(right);
|
||||||
|
|
||||||
if (grid_compare(c->status.grid, old_status.grid) == 0) {
|
if (grid_compare(c->status.status.grid, old_status.grid) == 0) {
|
||||||
screen_free(&old_status);
|
screen_free(&old_status);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -575,10 +590,11 @@ status_message_set(struct client *c, const char *fmt, ...)
|
|||||||
|
|
||||||
status_message_clear(c);
|
status_message_clear(c);
|
||||||
|
|
||||||
if (c->old_status == NULL) {
|
if (c->status.old_status == NULL) {
|
||||||
c->old_status = xmalloc(sizeof *c->old_status);
|
c->status.old_status = xmalloc(sizeof *c->status.old_status);
|
||||||
memcpy(c->old_status, &c->status, sizeof *c->old_status);
|
memcpy(c->status.old_status, &c->status.status,
|
||||||
screen_init(&c->status, c->tty.sx, 1, 0);
|
sizeof *c->status.old_status);
|
||||||
|
screen_init(&c->status.status, c->tty.sx, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
@@ -616,7 +632,7 @@ status_message_clear(struct client *c)
|
|||||||
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
|
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
|
||||||
c->flags |= CLIENT_REDRAW; /* screen was frozen and may have changed */
|
c->flags |= CLIENT_REDRAW; /* screen was frozen and may have changed */
|
||||||
|
|
||||||
screen_reinit(&c->status);
|
screen_reinit(&c->status.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear status line message after timer expires. */
|
/* Clear status line message after timer expires. */
|
||||||
@@ -637,11 +653,18 @@ status_message_redraw(struct client *c)
|
|||||||
struct screen old_status;
|
struct screen old_status;
|
||||||
size_t len;
|
size_t len;
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
|
u_int lines, offset;
|
||||||
|
|
||||||
if (c->tty.sx == 0 || c->tty.sy == 0)
|
if (c->tty.sx == 0 || c->tty.sy == 0)
|
||||||
return (0);
|
return (0);
|
||||||
memcpy(&old_status, &c->status, sizeof old_status);
|
memcpy(&old_status, &c->status.status, sizeof old_status);
|
||||||
screen_init(&c->status, c->tty.sx, 1, 0);
|
|
||||||
|
lines = status_line_size(c->session);
|
||||||
|
if (lines <= 1) {
|
||||||
|
lines = 1;
|
||||||
|
screen_init(&c->status.status, c->tty.sx, 1, 0);
|
||||||
|
} else
|
||||||
|
screen_init(&c->status.status, c->tty.sx, lines, 0);
|
||||||
|
|
||||||
len = screen_write_strlen("%s", c->message_string);
|
len = screen_write_strlen("%s", c->message_string);
|
||||||
if (len > c->tty.sx)
|
if (len > c->tty.sx)
|
||||||
@@ -649,16 +672,15 @@ status_message_redraw(struct client *c)
|
|||||||
|
|
||||||
style_apply(&gc, s->options, "message-style");
|
style_apply(&gc, s->options, "message-style");
|
||||||
|
|
||||||
screen_write_start(&ctx, NULL, &c->status);
|
screen_write_start(&ctx, NULL, &c->status.status);
|
||||||
|
|
||||||
screen_write_cursormove(&ctx, 0, 0);
|
screen_write_cursormove(&ctx, 0, 0);
|
||||||
screen_write_nputs(&ctx, len, &gc, "%s", c->message_string);
|
for (offset = 0; offset < lines * c->tty.sx; offset++)
|
||||||
for (; len < c->tty.sx; len++)
|
|
||||||
screen_write_putc(&ctx, &gc, ' ');
|
screen_write_putc(&ctx, &gc, ' ');
|
||||||
|
screen_write_cursormove(&ctx, 0, lines - 1);
|
||||||
|
screen_write_nputs(&ctx, len, &gc, "%s", c->message_string);
|
||||||
screen_write_stop(&ctx);
|
screen_write_stop(&ctx);
|
||||||
|
|
||||||
if (grid_compare(c->status.grid, old_status.grid) == 0) {
|
if (grid_compare(c->status.status.grid, old_status.grid) == 0) {
|
||||||
screen_free(&old_status);
|
screen_free(&old_status);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -689,10 +711,11 @@ status_prompt_set(struct client *c, const char *msg, const char *input,
|
|||||||
status_message_clear(c);
|
status_message_clear(c);
|
||||||
status_prompt_clear(c);
|
status_prompt_clear(c);
|
||||||
|
|
||||||
if (c->old_status == NULL) {
|
if (c->status.old_status == NULL) {
|
||||||
c->old_status = xmalloc(sizeof *c->old_status);
|
c->status.old_status = xmalloc(sizeof *c->status.old_status);
|
||||||
memcpy(c->old_status, &c->status, sizeof *c->old_status);
|
memcpy(c->status.old_status, &c->status.status,
|
||||||
screen_init(&c->status, c->tty.sx, 1, 0);
|
sizeof *c->status.old_status);
|
||||||
|
screen_init(&c->status.status, c->tty.sx, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
c->prompt_string = format_expand_time(ft, msg, t);
|
c->prompt_string = format_expand_time(ft, msg, t);
|
||||||
@@ -742,7 +765,7 @@ status_prompt_clear(struct client *c)
|
|||||||
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
|
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
|
||||||
c->flags |= CLIENT_REDRAW; /* screen was frozen and may have changed */
|
c->flags |= CLIENT_REDRAW; /* screen was frozen and may have changed */
|
||||||
|
|
||||||
screen_reinit(&c->status);
|
screen_reinit(&c->status.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update status line prompt with a new prompt string. */
|
/* Update status line prompt with a new prompt string. */
|
||||||
@@ -782,12 +805,19 @@ status_prompt_redraw(struct client *c)
|
|||||||
struct session *s = c->session;
|
struct session *s = c->session;
|
||||||
struct screen old_status;
|
struct screen old_status;
|
||||||
u_int i, offset, left, start, pcursor, pwidth, width;
|
u_int i, offset, left, start, pcursor, pwidth, width;
|
||||||
|
u_int lines;
|
||||||
struct grid_cell gc, cursorgc;
|
struct grid_cell gc, cursorgc;
|
||||||
|
|
||||||
if (c->tty.sx == 0 || c->tty.sy == 0)
|
if (c->tty.sx == 0 || c->tty.sy == 0)
|
||||||
return (0);
|
return (0);
|
||||||
memcpy(&old_status, &c->status, sizeof old_status);
|
memcpy(&old_status, &c->status.status, sizeof old_status);
|
||||||
screen_init(&c->status, c->tty.sx, 1, 0);
|
|
||||||
|
lines = status_line_size(c->session);
|
||||||
|
if (lines <= 1) {
|
||||||
|
lines = 1;
|
||||||
|
screen_init(&c->status.status, c->tty.sx, 1, 0);
|
||||||
|
} else
|
||||||
|
screen_init(&c->status.status, c->tty.sx, lines, 0);
|
||||||
|
|
||||||
if (c->prompt_mode == PROMPT_COMMAND)
|
if (c->prompt_mode == PROMPT_COMMAND)
|
||||||
style_apply(&gc, s->options, "message-command-style");
|
style_apply(&gc, s->options, "message-command-style");
|
||||||
@@ -801,11 +831,12 @@ status_prompt_redraw(struct client *c)
|
|||||||
if (start > c->tty.sx)
|
if (start > c->tty.sx)
|
||||||
start = c->tty.sx;
|
start = c->tty.sx;
|
||||||
|
|
||||||
screen_write_start(&ctx, NULL, &c->status);
|
screen_write_start(&ctx, NULL, &c->status.status);
|
||||||
|
screen_write_cursormove(&ctx, 0, 0);
|
||||||
|
for (offset = 0; offset < lines * c->tty.sx; offset++)
|
||||||
|
screen_write_putc(&ctx, &gc, ' ');
|
||||||
screen_write_cursormove(&ctx, 0, 0);
|
screen_write_cursormove(&ctx, 0, 0);
|
||||||
screen_write_nputs(&ctx, start, &gc, "%s", c->prompt_string);
|
screen_write_nputs(&ctx, start, &gc, "%s", c->prompt_string);
|
||||||
while (c->status.cx < screen_size_x(&c->status))
|
|
||||||
screen_write_putc(&ctx, &gc, ' ');
|
|
||||||
screen_write_cursormove(&ctx, start, 0);
|
screen_write_cursormove(&ctx, start, 0);
|
||||||
|
|
||||||
left = c->tty.sx - start;
|
left = c->tty.sx - start;
|
||||||
@@ -846,13 +877,14 @@ status_prompt_redraw(struct client *c)
|
|||||||
screen_write_cell(&ctx, &cursorgc);
|
screen_write_cell(&ctx, &cursorgc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c->status.cx < screen_size_x(&c->status) && c->prompt_index >= i)
|
if (c->status.status.cx < screen_size_x(&c->status.status) &&
|
||||||
|
c->prompt_index >= i)
|
||||||
screen_write_putc(&ctx, &cursorgc, ' ');
|
screen_write_putc(&ctx, &cursorgc, ' ');
|
||||||
|
|
||||||
finished:
|
finished:
|
||||||
screen_write_stop(&ctx);
|
screen_write_stop(&ctx);
|
||||||
|
|
||||||
if (grid_compare(c->status.grid, old_status.grid) == 0) {
|
if (grid_compare(c->status.status.grid, old_status.grid) == 0) {
|
||||||
screen_free(&old_status);
|
screen_free(&old_status);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -1305,6 +1337,7 @@ process_key:
|
|||||||
break;
|
break;
|
||||||
case '\033': /* Escape */
|
case '\033': /* Escape */
|
||||||
case '\003': /* C-c */
|
case '\003': /* C-c */
|
||||||
|
case '\007': /* C-g */
|
||||||
if (c->prompt_inputcb(c, c->prompt_data, NULL, 1) == 0)
|
if (c->prompt_inputcb(c, c->prompt_data, NULL, 1) == 0)
|
||||||
status_prompt_clear(c);
|
status_prompt_clear(c);
|
||||||
break;
|
break;
|
||||||
|
|||||||
174
tmux.1
174
tmux.1
@@ -855,6 +855,8 @@ the initial size is 80 x 24;
|
|||||||
and
|
and
|
||||||
.Fl y
|
.Fl y
|
||||||
can be used to specify a different size.
|
can be used to specify a different size.
|
||||||
|
.Ql -
|
||||||
|
uses the size of the current client if any.
|
||||||
.Pp
|
.Pp
|
||||||
If run from a terminal, any
|
If run from a terminal, any
|
||||||
.Xr termios 4
|
.Xr termios 4
|
||||||
@@ -966,7 +968,7 @@ show debugging information about jobs and terminals.
|
|||||||
Execute commands from
|
Execute commands from
|
||||||
.Ar path
|
.Ar path
|
||||||
(which may be a
|
(which may be a
|
||||||
.Xr glob 3
|
.Xr glob 7
|
||||||
pattern).
|
pattern).
|
||||||
If
|
If
|
||||||
.Fl q
|
.Fl q
|
||||||
@@ -980,22 +982,37 @@ them with
|
|||||||
and
|
and
|
||||||
.Em %endif
|
.Em %endif
|
||||||
lines.
|
lines.
|
||||||
|
Additional
|
||||||
|
.Em %elif
|
||||||
|
and
|
||||||
|
.Em %else
|
||||||
|
lines may also be used.
|
||||||
The argument to
|
The argument to
|
||||||
.Em %if
|
.Em %if
|
||||||
is expanded as a format and if it evaluates to false
|
and
|
||||||
(zero or empty), subsequent lines are ignored until
|
.Em %elif
|
||||||
|
is expanded as a format and if it evaluates to false (zero or empty),
|
||||||
|
subsequent lines are ignored until the next
|
||||||
|
.Em %elif ,
|
||||||
|
.Em %else
|
||||||
|
or
|
||||||
.Em %endif .
|
.Em %endif .
|
||||||
For example:
|
For example:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
%if #{==:#{host},myhost}
|
%if #{==:#{host},myhost}
|
||||||
set -g status-style bg=red
|
set -g status-style bg=red
|
||||||
|
%elif #{==:#{host},myotherhost}
|
||||||
|
set -g status-style bg=green
|
||||||
|
%else
|
||||||
|
set -g status-style bg=blue
|
||||||
%endif
|
%endif
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Will change the status line to red if running on
|
Will change the status line to red if running on
|
||||||
.Ql myhost .
|
.Ql myhost ,
|
||||||
.Em %if
|
green if running on
|
||||||
may not be nested.
|
.Ql myotherhost ,
|
||||||
|
or blue if running on another host.
|
||||||
.It Ic start-server
|
.It Ic start-server
|
||||||
.D1 (alias: Ic start )
|
.D1 (alias: Ic start )
|
||||||
Start the
|
Start the
|
||||||
@@ -1111,9 +1128,10 @@ The following commands are supported in copy mode:
|
|||||||
.It Li "end-of-line" Ta "$" Ta "C-e"
|
.It Li "end-of-line" Ta "$" Ta "C-e"
|
||||||
.It Li "goto-line <line>" Ta ":" Ta "g"
|
.It Li "goto-line <line>" Ta ":" Ta "g"
|
||||||
.It Li "halfpage-down" Ta "C-d" Ta "M-Down"
|
.It Li "halfpage-down" Ta "C-d" Ta "M-Down"
|
||||||
|
.It Li "halfpage-down-and-cancel" Ta "" Ta ""
|
||||||
.It Li "halfpage-up" Ta "C-u" Ta "M-Up"
|
.It Li "halfpage-up" Ta "C-u" Ta "M-Up"
|
||||||
.It Li "history-bottom" Ta "G" Ta "M-<"
|
.It Li "history-bottom" Ta "G" Ta "M->"
|
||||||
.It Li "history-top" Ta "g" Ta "M->"
|
.It Li "history-top" Ta "g" Ta "M-<"
|
||||||
.It Li "jump-again" Ta ";" Ta ";"
|
.It Li "jump-again" Ta ";" Ta ";"
|
||||||
.It Li "jump-backward <to>" Ta "F" Ta "F"
|
.It Li "jump-backward <to>" Ta "F" Ta "F"
|
||||||
.It Li "jump-forward <to>" Ta "f" Ta "f"
|
.It Li "jump-forward <to>" Ta "f" Ta "f"
|
||||||
@@ -1128,12 +1146,14 @@ The following commands are supported in copy mode:
|
|||||||
.It Li "next-word-end" Ta "e" Ta "M-f"
|
.It Li "next-word-end" Ta "e" Ta "M-f"
|
||||||
.It Li "other-end" Ta "o" Ta ""
|
.It Li "other-end" Ta "o" Ta ""
|
||||||
.It Li "page-down" Ta "C-f" Ta "PageDown"
|
.It Li "page-down" Ta "C-f" Ta "PageDown"
|
||||||
|
.It Li "page-down-and-cancel" Ta "" Ta ""
|
||||||
.It Li "page-up" Ta "C-b" Ta "PageUp"
|
.It Li "page-up" Ta "C-b" Ta "PageUp"
|
||||||
.It Li "previous-paragraph" Ta "{" Ta "M-{"
|
.It Li "previous-paragraph" Ta "{" Ta "M-{"
|
||||||
.It Li "previous-space" Ta "B" Ta ""
|
.It Li "previous-space" Ta "B" Ta ""
|
||||||
.It Li "previous-word" Ta "b" Ta "M-b"
|
.It Li "previous-word" Ta "b" Ta "M-b"
|
||||||
.It Li "rectangle-toggle" Ta "v" Ta "R"
|
.It Li "rectangle-toggle" Ta "v" Ta "R"
|
||||||
.It Li "scroll-down" Ta "C-e" Ta "C-Down"
|
.It Li "scroll-down" Ta "C-e" Ta "C-Down"
|
||||||
|
.It Li "scroll-down-and-cancel" Ta "" Ta ""
|
||||||
.It Li "scroll-up" Ta "C-y" Ta "C-Up"
|
.It Li "scroll-up" Ta "C-y" Ta "C-Up"
|
||||||
.It Li "search-again" Ta "n" Ta "n"
|
.It Li "search-again" Ta "n" Ta "n"
|
||||||
.It Li "search-backward <for>" Ta "?" Ta ""
|
.It Li "search-backward <for>" Ta "?" Ta ""
|
||||||
@@ -1147,6 +1167,11 @@ The following commands are supported in copy mode:
|
|||||||
.It Li "top-line" Ta "H" Ta "M-R"
|
.It Li "top-line" Ta "H" Ta "M-R"
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
|
The
|
||||||
|
.Ql -and-cancel
|
||||||
|
variants of some commands exit copy mode after they have completed (for copy
|
||||||
|
commands) or when the cursor reaches the bottom (for scrolling commands).
|
||||||
|
.Pp
|
||||||
The next and previous word keys use space and the
|
The next and previous word keys use space and the
|
||||||
.Ql - ,
|
.Ql - ,
|
||||||
.Ql _
|
.Ql _
|
||||||
@@ -1358,7 +1383,7 @@ the end of the visible pane.
|
|||||||
The default is to capture only the visible contents of the pane.
|
The default is to capture only the visible contents of the pane.
|
||||||
.It Xo
|
.It Xo
|
||||||
.Ic choose-client
|
.Ic choose-client
|
||||||
.Op Fl N
|
.Op Fl NZ
|
||||||
.Op Fl F Ar format
|
.Op Fl F Ar format
|
||||||
.Op Fl f Ar filter
|
.Op Fl f Ar filter
|
||||||
.Op Fl O Ar sort-order
|
.Op Fl O Ar sort-order
|
||||||
@@ -1367,6 +1392,8 @@ The default is to capture only the visible contents of the pane.
|
|||||||
.Xc
|
.Xc
|
||||||
Put a pane into client mode, allowing a client to be selected interactively from
|
Put a pane into client mode, allowing a client to be selected interactively from
|
||||||
a list.
|
a list.
|
||||||
|
.Fl Z
|
||||||
|
zooms the pane.
|
||||||
The following keys may be used in client mode:
|
The following keys may be used in client mode:
|
||||||
.Bl -column "Key" "Function" -offset indent
|
.Bl -column "Key" "Function" -offset indent
|
||||||
.It Sy "Key" Ta Sy "Function"
|
.It Sy "Key" Ta Sy "Function"
|
||||||
@@ -1417,7 +1444,7 @@ starts without the preview.
|
|||||||
This command works only if at least one client is attached.
|
This command works only if at least one client is attached.
|
||||||
.It Xo
|
.It Xo
|
||||||
.Ic choose-tree
|
.Ic choose-tree
|
||||||
.Op Fl Nsw
|
.Op Fl GNswZ
|
||||||
.Op Fl F Ar format
|
.Op Fl F Ar format
|
||||||
.Op Fl f Ar filter
|
.Op Fl f Ar filter
|
||||||
.Op Fl O Ar sort-order
|
.Op Fl O Ar sort-order
|
||||||
@@ -1430,12 +1457,16 @@ interactively from a list.
|
|||||||
starts with sessions collapsed and
|
starts with sessions collapsed and
|
||||||
.Fl w
|
.Fl w
|
||||||
with windows collapsed.
|
with windows collapsed.
|
||||||
|
.Fl Z
|
||||||
|
zooms the pane.
|
||||||
The following keys may be used in tree mode:
|
The following keys may be used in tree mode:
|
||||||
.Bl -column "Key" "Function" -offset indent
|
.Bl -column "Key" "Function" -offset indent
|
||||||
.It Sy "Key" Ta Sy "Function"
|
.It Sy "Key" Ta Sy "Function"
|
||||||
.It Li "Enter" Ta "Choose selected item"
|
.It Li "Enter" Ta "Choose selected item"
|
||||||
.It Li "Up" Ta "Select previous item"
|
.It Li "Up" Ta "Select previous item"
|
||||||
.It Li "Down" Ta "Select next item"
|
.It Li "Down" Ta "Select next item"
|
||||||
|
.It Li "x" Ta "Kill selected item"
|
||||||
|
.It Li "X" Ta "Kill tagged items"
|
||||||
.It Li "<" Ta "Scroll list of previews left"
|
.It Li "<" Ta "Scroll list of previews left"
|
||||||
.It Li ">" Ta "Scroll list of previews right"
|
.It Li ">" Ta "Scroll list of previews right"
|
||||||
.It Li "C-s" Ta "Search by name"
|
.It Li "C-s" Ta "Search by name"
|
||||||
@@ -1473,6 +1504,9 @@ If a filter would lead to an empty list, it is ignored.
|
|||||||
specifies the format for each item in the tree.
|
specifies the format for each item in the tree.
|
||||||
.Fl N
|
.Fl N
|
||||||
starts without the preview.
|
starts without the preview.
|
||||||
|
.Fl G
|
||||||
|
includes all sessions in any session groups in the tree rather than only the
|
||||||
|
first.
|
||||||
This command works only if at least one client is attached.
|
This command works only if at least one client is attached.
|
||||||
.It Xo
|
.It Xo
|
||||||
.Ic display-panes
|
.Ic display-panes
|
||||||
@@ -1778,15 +1812,15 @@ If
|
|||||||
.Fl a
|
.Fl a
|
||||||
is used, move to the next window with an alert.
|
is used, move to the next window with an alert.
|
||||||
.It Xo Ic pipe-pane
|
.It Xo Ic pipe-pane
|
||||||
.Op Fl o
|
.Op Fl IOo
|
||||||
.Op Fl t Ar target-pane
|
.Op Fl t Ar target-pane
|
||||||
.Op Ar shell-command
|
.Op Ar shell-command
|
||||||
.Xc
|
.Xc
|
||||||
.D1 (alias: Ic pipep )
|
.D1 (alias: Ic pipep )
|
||||||
Pipe any output sent by the program in
|
Pipe output sent by the program in
|
||||||
.Ar target-pane
|
.Ar target-pane
|
||||||
to a shell command.
|
to a shell command or vice versa.
|
||||||
A pane may only be piped to one command at a time, any existing pipe is
|
A pane may only be connected to one command at a time, any existing pipe is
|
||||||
closed before
|
closed before
|
||||||
.Ar shell-command
|
.Ar shell-command
|
||||||
is executed.
|
is executed.
|
||||||
@@ -1799,6 +1833,25 @@ If no
|
|||||||
.Ar shell-command
|
.Ar shell-command
|
||||||
is given, the current pipe (if any) is closed.
|
is given, the current pipe (if any) is closed.
|
||||||
.Pp
|
.Pp
|
||||||
|
.Fl I
|
||||||
|
and
|
||||||
|
.Fl O
|
||||||
|
specify which of the
|
||||||
|
.Ar shell-command
|
||||||
|
output streams are connected to the pane:
|
||||||
|
with
|
||||||
|
.Fl I
|
||||||
|
stdout is connected (so anything
|
||||||
|
.Ar shell-command
|
||||||
|
prints is written to the pane as if it were typed);
|
||||||
|
with
|
||||||
|
.Fl O
|
||||||
|
stdin is connected (so any output in the pane is piped to
|
||||||
|
.Ar shell-command ) .
|
||||||
|
Both may be used together and if neither are specified,
|
||||||
|
.Fl O
|
||||||
|
is used.
|
||||||
|
.Pp
|
||||||
The
|
The
|
||||||
.Fl o
|
.Fl o
|
||||||
option only opens a new pipe if no previous pipe exists, allowing a pipe to
|
option only opens a new pipe if no previous pipe exists, allowing a pipe to
|
||||||
@@ -1909,8 +1962,8 @@ lower) with
|
|||||||
.Fl U
|
.Fl U
|
||||||
or downward (numerically higher).
|
or downward (numerically higher).
|
||||||
.It Xo Ic select-layout
|
.It Xo Ic select-layout
|
||||||
.Op Fl nop
|
.Op Fl Enop
|
||||||
.Op Fl t Ar target-window
|
.Op Fl t Ar target-pane
|
||||||
.Op Ar layout-name
|
.Op Ar layout-name
|
||||||
.Xc
|
.Xc
|
||||||
.D1 (alias: Ic selectl )
|
.D1 (alias: Ic selectl )
|
||||||
@@ -1928,6 +1981,8 @@ and
|
|||||||
commands.
|
commands.
|
||||||
.Fl o
|
.Fl o
|
||||||
applies the last set layout if possible (undoes the most recent layout change).
|
applies the last set layout if possible (undoes the most recent layout change).
|
||||||
|
.Fl E
|
||||||
|
spreads the current pane and any panes next to it out evenly.
|
||||||
.It Xo Ic select-pane
|
.It Xo Ic select-pane
|
||||||
.Op Fl DdegLlMmRU
|
.Op Fl DdegLlMmRU
|
||||||
.Op Fl P Ar style
|
.Op Fl P Ar style
|
||||||
@@ -2460,6 +2515,11 @@ Set the time in milliseconds for which
|
|||||||
waits after an escape is input to determine if it is part of a function or meta
|
waits after an escape is input to determine if it is part of a function or meta
|
||||||
key sequences.
|
key sequences.
|
||||||
The default is 500 milliseconds.
|
The default is 500 milliseconds.
|
||||||
|
.It Xo Ic exit-empty
|
||||||
|
.Op Ic on | off
|
||||||
|
.Xc
|
||||||
|
If enabled (the default), the server will exit when there are no active
|
||||||
|
sessions.
|
||||||
.It Xo Ic exit-unattached
|
.It Xo Ic exit-unattached
|
||||||
.Op Ic on | off
|
.Op Ic on | off
|
||||||
.Xc
|
.Xc
|
||||||
@@ -2697,8 +2757,7 @@ to
|
|||||||
from the 256-colour set,
|
from the 256-colour set,
|
||||||
.Ic default ,
|
.Ic default ,
|
||||||
or a hexadecimal RGB string such as
|
or a hexadecimal RGB string such as
|
||||||
.Ql #ffffff ,
|
.Ql #ffffff .
|
||||||
which chooses the closest match from the default 256-colour set.
|
|
||||||
.Pp
|
.Pp
|
||||||
The attributes is either
|
The attributes is either
|
||||||
.Ic none
|
.Ic none
|
||||||
@@ -3008,7 +3067,7 @@ and poor for interactive programs such as shells.
|
|||||||
.Xc
|
.Xc
|
||||||
Allow programs to change the window name using a terminal escape
|
Allow programs to change the window name using a terminal escape
|
||||||
sequence (\eek...\ee\e\e).
|
sequence (\eek...\ee\e\e).
|
||||||
The default is on.
|
The default is off.
|
||||||
.Pp
|
.Pp
|
||||||
.It Xo Ic alternate-screen
|
.It Xo Ic alternate-screen
|
||||||
.Op Ic on | off
|
.Op Ic on | off
|
||||||
@@ -3336,7 +3395,11 @@ layout after every
|
|||||||
set-hook after-split-window "selectl even-vertical"
|
set-hook after-split-window "selectl even-vertical"
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
In addition, the following hooks are available:
|
All the notifications listed in the
|
||||||
|
.Sx CONTROL MODE
|
||||||
|
section are hooks (without any arguments), except
|
||||||
|
.Ic %exit .
|
||||||
|
The following additional hooks are available:
|
||||||
.Bl -tag -width "XXXXXXXXXXXXXXXXXXXXXX"
|
.Bl -tag -width "XXXXXXXXXXXXXXXXXXXXXX"
|
||||||
.It alert-activity
|
.It alert-activity
|
||||||
Run when a window has activity.
|
Run when a window has activity.
|
||||||
@@ -3364,6 +3427,14 @@ Run when the program running in a pane exits, but
|
|||||||
is on so the pane has not closed.
|
is on so the pane has not closed.
|
||||||
.It pane-exited
|
.It pane-exited
|
||||||
Run when the program running in a pane exits.
|
Run when the program running in a pane exits.
|
||||||
|
.It pane-focus-in
|
||||||
|
Run when the focus enters a pane, if the
|
||||||
|
.Ic focus-events
|
||||||
|
option is on.
|
||||||
|
.It pane-focus-out
|
||||||
|
Run when the focus exits a pane, if the
|
||||||
|
.Ic focus-events
|
||||||
|
option is on.
|
||||||
.It pane-set-clipboard
|
.It pane-set-clipboard
|
||||||
Run when the terminal clipboard is set using the
|
Run when the terminal clipboard is set using the
|
||||||
.Xr xterm 1
|
.Xr xterm 1
|
||||||
@@ -3385,12 +3456,14 @@ Run when a window is unlinked from a session.
|
|||||||
Hooks are managed with these commands:
|
Hooks are managed with these commands:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Xo Ic set-hook
|
.It Xo Ic set-hook
|
||||||
.Op Fl gu
|
.Op Fl gRu
|
||||||
.Op Fl t Ar target-session
|
.Op Fl t Ar target-session
|
||||||
.Ar hook-name
|
.Ar hook-name
|
||||||
.Ar command
|
.Ar command
|
||||||
.Xc
|
.Xc
|
||||||
Sets (or with
|
Without
|
||||||
|
.Fl R ,
|
||||||
|
sets (or with
|
||||||
.Fl u
|
.Fl u
|
||||||
unsets) hook
|
unsets) hook
|
||||||
.Ar hook-name
|
.Ar hook-name
|
||||||
@@ -3406,6 +3479,12 @@ hooks (for
|
|||||||
with
|
with
|
||||||
.Fl t ) .
|
.Fl t ) .
|
||||||
Like options, session hooks inherit from the global ones.
|
Like options, session hooks inherit from the global ones.
|
||||||
|
.Pp
|
||||||
|
With
|
||||||
|
.Fl R ,
|
||||||
|
run
|
||||||
|
.Ar hook-name
|
||||||
|
immediately.
|
||||||
.It Xo Ic show-hooks
|
.It Xo Ic show-hooks
|
||||||
.Op Fl g
|
.Op Fl g
|
||||||
.Op Fl t Ar target-session
|
.Op Fl t Ar target-session
|
||||||
@@ -3435,8 +3514,8 @@ The following mouse events are available:
|
|||||||
.It Li "MouseDown1" Ta "MouseUp1" Ta "MouseDrag1" Ta "MouseDragEnd1"
|
.It Li "MouseDown1" Ta "MouseUp1" Ta "MouseDrag1" Ta "MouseDragEnd1"
|
||||||
.It Li "MouseDown2" Ta "MouseUp2" Ta "MouseDrag2" Ta "MouseDragEnd2"
|
.It Li "MouseDown2" Ta "MouseUp2" Ta "MouseDrag2" Ta "MouseDragEnd2"
|
||||||
.It Li "MouseDown3" Ta "MouseUp3" Ta "MouseDrag3" Ta "MouseDragEnd3"
|
.It Li "MouseDown3" Ta "MouseUp3" Ta "MouseDrag3" Ta "MouseDragEnd3"
|
||||||
.It Li "DoubleClick1" Ta "DoubleClick2" Ta "DoubleClick3" Ta "WheelUp"
|
.It Li "DoubleClick1" Ta "DoubleClick2" Ta "DoubleClick3"
|
||||||
.It Li "TripleClick1" Ta "TripleClick2" Ta "TripleClick3" Ta "WheelDown"
|
.It Li "TripleClick1" Ta "TripleClick2" Ta "TripleClick3"
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
Each should be suffixed with a location, for example
|
Each should be suffixed with a location, for example
|
||||||
@@ -3485,11 +3564,17 @@ The possible variables are listed in the table below, or the name of a
|
|||||||
.Nm
|
.Nm
|
||||||
option may be used for an option's value.
|
option may be used for an option's value.
|
||||||
Some variables have a shorter alias such as
|
Some variables have a shorter alias such as
|
||||||
.Ql #S ,
|
.Ql #S ;
|
||||||
and
|
|
||||||
.Ql ##
|
.Ql ##
|
||||||
is replaced by a single
|
is replaced by a single
|
||||||
.Ql # .
|
.Ql # ,
|
||||||
|
.Ql #,
|
||||||
|
by a
|
||||||
|
.Ql \&,
|
||||||
|
and
|
||||||
|
.Ql #}
|
||||||
|
by a
|
||||||
|
.Ql } .
|
||||||
.Pp
|
.Pp
|
||||||
Conditionals are available by prefixing with
|
Conditionals are available by prefixing with
|
||||||
.Ql \&?
|
.Ql \&?
|
||||||
@@ -3511,6 +3596,22 @@ if
|
|||||||
is enabled, or
|
is enabled, or
|
||||||
.Ql no
|
.Ql no
|
||||||
if not.
|
if not.
|
||||||
|
Conditionals can be nested arbitrarily.
|
||||||
|
Inside a conditional,
|
||||||
|
.Ql \&,
|
||||||
|
and
|
||||||
|
.Ql }
|
||||||
|
must be escaped as
|
||||||
|
.Ql #,
|
||||||
|
and
|
||||||
|
.Ql #} ,
|
||||||
|
unless they are part of a
|
||||||
|
.Ql #{...}
|
||||||
|
replacement.
|
||||||
|
For example:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
#{?pane_in_mode,#[fg=white#,bg=red],#[fg=red#,bg=white]}#W .
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Comparisons may be expressed by prefixing two comma-separated
|
Comparisons may be expressed by prefixing two comma-separated
|
||||||
alternatives by
|
alternatives by
|
||||||
@@ -3538,7 +3639,7 @@ and
|
|||||||
.Ql &&
|
.Ql &&
|
||||||
evaluate to true if either or both of two comma-separated alternatives are
|
evaluate to true if either or both of two comma-separated alternatives are
|
||||||
true, for example
|
true, for example
|
||||||
.Ql #{||,#{pane_in_mode},#{alternate_on}} .
|
.Ql #{||:#{pane_in_mode},#{alternate_on}} .
|
||||||
A
|
A
|
||||||
.Ql C
|
.Ql C
|
||||||
performs a search for an
|
performs a search for an
|
||||||
@@ -3638,7 +3739,7 @@ The following variables are available, where appropriate:
|
|||||||
.It Li "cursor_y" Ta "" Ta "Cursor Y position in pane"
|
.It Li "cursor_y" Ta "" Ta "Cursor Y position in pane"
|
||||||
.It Li "history_bytes" Ta "" Ta "Number of bytes in window history"
|
.It Li "history_bytes" Ta "" Ta "Number of bytes in window history"
|
||||||
.It Li "history_limit" Ta "" Ta "Maximum window history lines"
|
.It Li "history_limit" Ta "" Ta "Maximum window history lines"
|
||||||
.It Li "history_size" Ta "" Ta "Size of history in bytes"
|
.It Li "history_size" Ta "" Ta "Size of history in lines"
|
||||||
.It Li "hook" Ta "" Ta "Name of running hook, if any"
|
.It Li "hook" Ta "" Ta "Name of running hook, if any"
|
||||||
.It Li "hook_pane" Ta "" Ta "ID of pane where hook was run, if any"
|
.It Li "hook_pane" Ta "" Ta "ID of pane where hook was run, if any"
|
||||||
.It Li "hook_session" Ta "" Ta "ID of session where hook was run, if any"
|
.It Li "hook_session" Ta "" Ta "ID of session where hook was run, if any"
|
||||||
@@ -3685,6 +3786,7 @@ The following variables are available, where appropriate:
|
|||||||
.It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane"
|
.It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane"
|
||||||
.It Li "pane_width" Ta "" Ta "Width of pane"
|
.It Li "pane_width" Ta "" Ta "Width of pane"
|
||||||
.It Li "pid" Ta "" Ta "Server PID"
|
.It Li "pid" Ta "" Ta "Server PID"
|
||||||
|
.It Li "rectangle_toggle" Ta "" Ta "1 if rectangle selection is activated"
|
||||||
.It Li "scroll_region_lower" Ta "" Ta "Bottom of scroll region in pane"
|
.It Li "scroll_region_lower" Ta "" Ta "Bottom of scroll region in pane"
|
||||||
.It Li "scroll_region_upper" Ta "" Ta "Top of scroll region in pane"
|
.It Li "scroll_region_upper" Ta "" Ta "Top of scroll region in pane"
|
||||||
.It Li "scroll_position" Ta "" Ta "Scroll position in copy mode"
|
.It Li "scroll_position" Ta "" Ta "Scroll position in copy mode"
|
||||||
@@ -3696,6 +3798,8 @@ The following variables are available, where appropriate:
|
|||||||
.It Li "session_format" Ta "" Ta "1 if format is for a session (not assuming the current)"
|
.It Li "session_format" Ta "" Ta "1 if format is for a session (not assuming the current)"
|
||||||
.It Li "session_last_attached" Ta "" Ta "Time session last attached"
|
.It Li "session_last_attached" Ta "" Ta "Time session last attached"
|
||||||
.It Li "session_group" Ta "" Ta "Name of session group"
|
.It Li "session_group" Ta "" Ta "Name of session group"
|
||||||
|
.It Li "session_group_size" Ta "" Ta "Size of session group"
|
||||||
|
.It Li "session_group_list" Ta "" Ta "List of sessions in group"
|
||||||
.It Li "session_grouped" Ta "" Ta "1 if session in a group"
|
.It Li "session_grouped" Ta "" Ta "1 if session in a group"
|
||||||
.It Li "session_height" Ta "" Ta "Height of session"
|
.It Li "session_height" Ta "" Ta "Height of session"
|
||||||
.It Li "session_id" Ta "" Ta "Unique session ID"
|
.It Li "session_id" Ta "" Ta "Unique session ID"
|
||||||
@@ -3764,7 +3868,9 @@ for
|
|||||||
or
|
or
|
||||||
.Ic new-session ) .
|
.Ic new-session ) .
|
||||||
.It
|
.It
|
||||||
An escape sequence:
|
An escape sequence (if the
|
||||||
|
.Ic allow-rename
|
||||||
|
option is turned on):
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
$ printf '\e033kWINDOW_NAME\e033\e\e'
|
$ printf '\e033kWINDOW_NAME\e033\e\e'
|
||||||
.Ed
|
.Ed
|
||||||
@@ -4077,7 +4183,7 @@ The buffer commands are as follows:
|
|||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Xo
|
.It Xo
|
||||||
.Ic choose-buffer
|
.Ic choose-buffer
|
||||||
.Op Fl N
|
.Op Fl NZ
|
||||||
.Op Fl F Ar format
|
.Op Fl F Ar format
|
||||||
.Op Fl f Ar filter
|
.Op Fl f Ar filter
|
||||||
.Op Fl O Ar sort-order
|
.Op Fl O Ar sort-order
|
||||||
@@ -4086,10 +4192,12 @@ The buffer commands are as follows:
|
|||||||
.Xc
|
.Xc
|
||||||
Put a pane into buffer mode, where a buffer may be chosen interactively from
|
Put a pane into buffer mode, where a buffer may be chosen interactively from
|
||||||
a list.
|
a list.
|
||||||
|
.Fl Z
|
||||||
|
zooms the pane.
|
||||||
The following keys may be used in buffer mode:
|
The following keys may be used in buffer mode:
|
||||||
.Bl -column "Key" "Function" -offset indent
|
.Bl -column "Key" "Function" -offset indent
|
||||||
.It Sy "Key" Ta Sy "Function"
|
.It Sy "Key" Ta Sy "Function"
|
||||||
.It Li "Enter" Ta "Choose selected buffer"
|
.It Li "Enter" Ta "Paste selected buffer"
|
||||||
.It Li "Up" Ta "Select previous buffer"
|
.It Li "Up" Ta "Select previous buffer"
|
||||||
.It Li "Down" Ta "Select next buffer"
|
.It Li "Down" Ta "Select next buffer"
|
||||||
.It Li "C-s" Ta "Search by name or content"
|
.It Li "C-s" Ta "Search by name or content"
|
||||||
@@ -4097,6 +4205,8 @@ The following keys may be used in buffer mode:
|
|||||||
.It Li "t" Ta "Toggle if buffer is tagged"
|
.It Li "t" Ta "Toggle if buffer is tagged"
|
||||||
.It Li "T" Ta "Tag no buffers"
|
.It Li "T" Ta "Tag no buffers"
|
||||||
.It Li "C-t" Ta "Tag all buffers"
|
.It Li "C-t" Ta "Tag all buffers"
|
||||||
|
.It Li "p" Ta "Paste selected buffer"
|
||||||
|
.It Li "P" Ta "Paste tagged buffers"
|
||||||
.It Li "d" Ta "Delete selected buffer"
|
.It Li "d" Ta "Delete selected buffer"
|
||||||
.It Li "D" Ta "Delete tagged buffers"
|
.It Li "D" Ta "Delete tagged buffers"
|
||||||
.It Li "f" Ta "Enter a format to filter items"
|
.It Li "f" Ta "Enter a format to filter items"
|
||||||
|
|||||||
43
tmux.c
43
tmux.c
@@ -44,7 +44,7 @@ int ptm_fd = -1;
|
|||||||
const char *shell_command;
|
const char *shell_command;
|
||||||
|
|
||||||
static __dead void usage(void);
|
static __dead void usage(void);
|
||||||
static char *make_label(const char *);
|
static char *make_label(const char *, char **);
|
||||||
|
|
||||||
static const char *getshell(void);
|
static const char *getshell(void);
|
||||||
static int checkshell(const char *);
|
static int checkshell(const char *);
|
||||||
@@ -106,12 +106,13 @@ areshell(const char *shell)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
make_label(const char *label)
|
make_label(const char *label, char **cause)
|
||||||
{
|
{
|
||||||
char *base, resolved[PATH_MAX], *path, *s;
|
char *base, resolved[PATH_MAX], *path, *s;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
int saved_errno;
|
|
||||||
|
*cause = NULL;
|
||||||
|
|
||||||
if (label == NULL)
|
if (label == NULL)
|
||||||
label = "default";
|
label = "default";
|
||||||
@@ -121,11 +122,16 @@ make_label(const char *label)
|
|||||||
xasprintf(&base, "%s/tmux-%ld", s, (long)uid);
|
xasprintf(&base, "%s/tmux-%ld", s, (long)uid);
|
||||||
else
|
else
|
||||||
xasprintf(&base, "%s/tmux-%ld", _PATH_TMP, (long)uid);
|
xasprintf(&base, "%s/tmux-%ld", _PATH_TMP, (long)uid);
|
||||||
|
if (realpath(base, resolved) == NULL &&
|
||||||
if (mkdir(base, S_IRWXU) != 0 && errno != EEXIST)
|
strlcpy(resolved, base, sizeof resolved) >= sizeof resolved) {
|
||||||
|
errno = ERANGE;
|
||||||
|
free(base);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
if (lstat(base, &sb) != 0)
|
if (mkdir(resolved, S_IRWXU) != 0 && errno != EEXIST)
|
||||||
|
goto fail;
|
||||||
|
if (lstat(resolved, &sb) != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
if (!S_ISDIR(sb.st_mode)) {
|
if (!S_ISDIR(sb.st_mode)) {
|
||||||
errno = ENOTDIR;
|
errno = ENOTDIR;
|
||||||
@@ -135,18 +141,11 @@ make_label(const char *label)
|
|||||||
errno = EACCES;
|
errno = EACCES;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (realpath(base, resolved) == NULL)
|
|
||||||
strlcpy(resolved, base, sizeof resolved);
|
|
||||||
xasprintf(&path, "%s/%s", resolved, label);
|
xasprintf(&path, "%s/%s", resolved, label);
|
||||||
|
|
||||||
free(base);
|
|
||||||
return (path);
|
return (path);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
saved_errno = errno;
|
xasprintf(cause, "error creating %s (%s)", resolved, strerror(errno));
|
||||||
free(base);
|
|
||||||
errno = saved_errno;
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,9 +187,9 @@ find_home(void)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *path, *label, **var;
|
char *path, *label, *cause, **var;
|
||||||
char tmp[PATH_MAX];
|
char tmp[PATH_MAX];
|
||||||
const char *s, *shell;
|
const char *s, *shell, *cwd;
|
||||||
int opt, flags, keys;
|
int opt, flags, keys;
|
||||||
const struct options_table_entry *oe;
|
const struct options_table_entry *oe;
|
||||||
|
|
||||||
@@ -294,8 +293,9 @@ main(int argc, char **argv)
|
|||||||
global_environ = environ_create();
|
global_environ = environ_create();
|
||||||
for (var = environ; *var != NULL; var++)
|
for (var = environ; *var != NULL; var++)
|
||||||
environ_put(global_environ, *var);
|
environ_put(global_environ, *var);
|
||||||
if (getcwd(tmp, sizeof tmp) != NULL)
|
if ((cwd = getenv("PWD")) == NULL &&
|
||||||
environ_set(global_environ, "PWD", "%s", tmp);
|
(cwd = getcwd(tmp, sizeof tmp)) != NULL)
|
||||||
|
environ_set(global_environ, "PWD", "%s", cwd);
|
||||||
|
|
||||||
global_options = options_create(NULL);
|
global_options = options_create(NULL);
|
||||||
global_s_options = options_create(NULL);
|
global_s_options = options_create(NULL);
|
||||||
@@ -340,8 +340,11 @@ main(int argc, char **argv)
|
|||||||
path[strcspn(path, ",")] = '\0';
|
path[strcspn(path, ",")] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (path == NULL && (path = make_label(label)) == NULL) {
|
if (path == NULL && (path = make_label(label, &cause)) == NULL) {
|
||||||
fprintf(stderr, "can't create socket: %s\n", strerror(errno));
|
if (cause != NULL) {
|
||||||
|
fprintf(stderr, "%s\n", cause);
|
||||||
|
free(cause);
|
||||||
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
socket_path = path;
|
socket_path = path;
|
||||||
|
|||||||
169
tmux.h
169
tmux.h
@@ -19,8 +19,6 @@
|
|||||||
#ifndef TMUX_H
|
#ifndef TMUX_H
|
||||||
#define TMUX_H
|
#define TMUX_H
|
||||||
|
|
||||||
#define PROTOCOL_VERSION 8
|
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
|
||||||
@@ -56,6 +54,9 @@ struct session;
|
|||||||
struct tmuxpeer;
|
struct tmuxpeer;
|
||||||
struct tmuxproc;
|
struct tmuxproc;
|
||||||
|
|
||||||
|
/* Client-server protocol version. */
|
||||||
|
#define PROTOCOL_VERSION 8
|
||||||
|
|
||||||
/* Default global configuration file. */
|
/* Default global configuration file. */
|
||||||
#ifndef TMUX_CONF
|
#ifndef TMUX_CONF
|
||||||
#define TMUX_CONF "/etc/tmux.conf"
|
#define TMUX_CONF "/etc/tmux.conf"
|
||||||
@@ -140,6 +141,9 @@ enum {
|
|||||||
KEYC_FOCUS_IN = KEYC_BASE,
|
KEYC_FOCUS_IN = KEYC_BASE,
|
||||||
KEYC_FOCUS_OUT,
|
KEYC_FOCUS_OUT,
|
||||||
|
|
||||||
|
/* "Any" key, used if not found in key table. */
|
||||||
|
KEYC_ANY,
|
||||||
|
|
||||||
/* Paste brackets. */
|
/* Paste brackets. */
|
||||||
KEYC_PASTE_START,
|
KEYC_PASTE_START,
|
||||||
KEYC_PASTE_END,
|
KEYC_PASTE_END,
|
||||||
@@ -403,6 +407,7 @@ enum tty_code_code {
|
|||||||
TTYC_MS,
|
TTYC_MS,
|
||||||
TTYC_OP,
|
TTYC_OP,
|
||||||
TTYC_REV,
|
TTYC_REV,
|
||||||
|
TTYC_RGB,
|
||||||
TTYC_RI,
|
TTYC_RI,
|
||||||
TTYC_RMACS,
|
TTYC_RMACS,
|
||||||
TTYC_RMCUP,
|
TTYC_RMCUP,
|
||||||
@@ -510,10 +515,11 @@ struct msg_stderr_data {
|
|||||||
#define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ALL)
|
#define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ALL)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A single UTF-8 character. UTF8_SIZE must be big enough to hold at least one
|
* A single UTF-8 character. UTF8_SIZE must be big enough to hold
|
||||||
* combining character as well.
|
* combining characters as well, currently at most five (of three
|
||||||
|
* bytes) are supported.
|
||||||
*/
|
*/
|
||||||
#define UTF8_SIZE 9
|
#define UTF8_SIZE 18
|
||||||
struct utf8_data {
|
struct utf8_data {
|
||||||
u_char data[UTF8_SIZE];
|
u_char data[UTF8_SIZE];
|
||||||
|
|
||||||
@@ -554,6 +560,7 @@ enum utf8_state {
|
|||||||
/* Grid line flags. */
|
/* Grid line flags. */
|
||||||
#define GRID_LINE_WRAPPED 0x1
|
#define GRID_LINE_WRAPPED 0x1
|
||||||
#define GRID_LINE_EXTENDED 0x2
|
#define GRID_LINE_EXTENDED 0x2
|
||||||
|
#define GRID_LINE_DEAD 0x4
|
||||||
|
|
||||||
/* Grid cell data. */
|
/* Grid cell data. */
|
||||||
struct grid_cell {
|
struct grid_cell {
|
||||||
@@ -624,6 +631,9 @@ struct job {
|
|||||||
JOB_CLOSED
|
JOB_CLOSED
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
|
int flags;
|
||||||
|
#define JOB_NOWAIT 0x1
|
||||||
|
|
||||||
char *cmd;
|
char *cmd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status;
|
int status;
|
||||||
@@ -640,32 +650,12 @@ struct job {
|
|||||||
};
|
};
|
||||||
LIST_HEAD(joblist, job);
|
LIST_HEAD(joblist, job);
|
||||||
|
|
||||||
/* Screen selection. */
|
|
||||||
struct screen_sel {
|
|
||||||
int flag;
|
|
||||||
int hidden;
|
|
||||||
|
|
||||||
int rectflag;
|
|
||||||
enum {
|
|
||||||
LINE_SEL_NONE,
|
|
||||||
LINE_SEL_LEFT_RIGHT,
|
|
||||||
LINE_SEL_RIGHT_LEFT,
|
|
||||||
} lineflag;
|
|
||||||
|
|
||||||
int modekeys;
|
|
||||||
|
|
||||||
u_int sx;
|
|
||||||
u_int sy;
|
|
||||||
|
|
||||||
u_int ex;
|
|
||||||
u_int ey;
|
|
||||||
|
|
||||||
struct grid_cell cell;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Virtual screen. */
|
/* Virtual screen. */
|
||||||
|
struct screen_sel;
|
||||||
|
struct screen_titles;
|
||||||
struct screen {
|
struct screen {
|
||||||
char *title;
|
char *title;
|
||||||
|
struct screen_titles *titles;
|
||||||
|
|
||||||
struct grid *grid; /* grid data */
|
struct grid *grid; /* grid data */
|
||||||
|
|
||||||
@@ -682,7 +672,7 @@ struct screen {
|
|||||||
|
|
||||||
bitstr_t *tabs;
|
bitstr_t *tabs;
|
||||||
|
|
||||||
struct screen_sel sel;
|
struct screen_sel *sel;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Screen write context. */
|
/* Screen write context. */
|
||||||
@@ -729,28 +719,6 @@ struct window_mode {
|
|||||||
};
|
};
|
||||||
#define WINDOW_MODE_TIMEOUT 180
|
#define WINDOW_MODE_TIMEOUT 180
|
||||||
|
|
||||||
/* Structures for choose mode. */
|
|
||||||
struct window_choose_data {
|
|
||||||
struct client *start_client;
|
|
||||||
struct session *start_session;
|
|
||||||
|
|
||||||
u_int idx;
|
|
||||||
int type;
|
|
||||||
#define TREE_OTHER 0x0
|
|
||||||
#define TREE_WINDOW 0x1
|
|
||||||
#define TREE_SESSION 0x2
|
|
||||||
|
|
||||||
struct session *tree_session; /* session of items in tree */
|
|
||||||
|
|
||||||
struct winlink *wl;
|
|
||||||
int pane_id;
|
|
||||||
|
|
||||||
char *ft_template;
|
|
||||||
struct format_tree *ft;
|
|
||||||
|
|
||||||
char *command;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Child window structure. */
|
/* Child window structure. */
|
||||||
struct window_pane {
|
struct window_pane {
|
||||||
u_int id;
|
u_int id;
|
||||||
@@ -780,6 +748,8 @@ struct window_pane {
|
|||||||
#define PANE_INPUTOFF 0x40
|
#define PANE_INPUTOFF 0x40
|
||||||
#define PANE_CHANGED 0x80
|
#define PANE_CHANGED 0x80
|
||||||
#define PANE_EXITED 0x100
|
#define PANE_EXITED 0x100
|
||||||
|
#define PANE_STATUSREADY 0x200
|
||||||
|
#define PANE_STATUSDRAWN 0x400
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
@@ -857,12 +827,11 @@ struct window {
|
|||||||
int flags;
|
int flags;
|
||||||
#define WINDOW_BELL 0x1
|
#define WINDOW_BELL 0x1
|
||||||
#define WINDOW_ACTIVITY 0x2
|
#define WINDOW_ACTIVITY 0x2
|
||||||
/* 0x4 unused */
|
#define WINDOW_SILENCE 0x4
|
||||||
#define WINDOW_SILENCE 0x8
|
#define WINDOW_ZOOMED 0x8
|
||||||
#define WINDOW_ZOOMED 0x1000
|
#define WINDOW_FORCEWIDTH 0x10
|
||||||
#define WINDOW_FORCEWIDTH 0x2000
|
#define WINDOW_FORCEHEIGHT 0x20
|
||||||
#define WINDOW_FORCEHEIGHT 0x4000
|
#define WINDOW_STYLECHANGED 0x40
|
||||||
#define WINDOW_STYLECHANGED 0x8000
|
|
||||||
#define WINDOW_ALERTFLAGS (WINDOW_BELL|WINDOW_ACTIVITY|WINDOW_SILENCE)
|
#define WINDOW_ALERTFLAGS (WINDOW_BELL|WINDOW_ACTIVITY|WINDOW_SILENCE)
|
||||||
|
|
||||||
int alerts_queued;
|
int alerts_queued;
|
||||||
@@ -1311,6 +1280,13 @@ struct cmd_entry {
|
|||||||
enum cmd_retval (*exec)(struct cmd *, struct cmdq_item *);
|
enum cmd_retval (*exec)(struct cmd *, struct cmdq_item *);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Status line. */
|
||||||
|
struct status_line {
|
||||||
|
struct event timer;
|
||||||
|
struct screen status;
|
||||||
|
struct screen *old_status;
|
||||||
|
};
|
||||||
|
|
||||||
/* Client connection. */
|
/* Client connection. */
|
||||||
typedef int (*prompt_input_cb)(struct client *, void *, const char *, int);
|
typedef int (*prompt_input_cb)(struct client *, void *, const char *, int);
|
||||||
typedef void (*prompt_free_cb)(void *);
|
typedef void (*prompt_free_cb)(void *);
|
||||||
@@ -1353,10 +1329,7 @@ struct client {
|
|||||||
struct event click_timer;
|
struct event click_timer;
|
||||||
u_int click_button;
|
u_int click_button;
|
||||||
|
|
||||||
struct event status_timer;
|
struct status_line status;
|
||||||
struct screen status;
|
|
||||||
|
|
||||||
struct screen *old_status;
|
|
||||||
|
|
||||||
#define CLIENT_TERMINAL 0x1
|
#define CLIENT_TERMINAL 0x1
|
||||||
#define CLIENT_LOGIN 0x2
|
#define CLIENT_LOGIN 0x2
|
||||||
@@ -1381,6 +1354,7 @@ struct client {
|
|||||||
#define CLIENT_DOUBLECLICK 0x100000
|
#define CLIENT_DOUBLECLICK 0x100000
|
||||||
#define CLIENT_TRIPLECLICK 0x200000
|
#define CLIENT_TRIPLECLICK 0x200000
|
||||||
#define CLIENT_SIZECHANGED 0x400000
|
#define CLIENT_SIZECHANGED 0x400000
|
||||||
|
#define CLIENT_STATUSOFF 0x800000
|
||||||
int flags;
|
int flags;
|
||||||
struct key_table *keytable;
|
struct key_table *keytable;
|
||||||
|
|
||||||
@@ -1388,6 +1362,7 @@ struct client {
|
|||||||
void (*identify_callback)(struct client *,
|
void (*identify_callback)(struct client *,
|
||||||
struct window_pane *);
|
struct window_pane *);
|
||||||
void *identify_callback_data;
|
void *identify_callback_data;
|
||||||
|
struct cmdq_item *identify_callback_item;
|
||||||
|
|
||||||
char *message_string;
|
char *message_string;
|
||||||
struct event message_timer;
|
struct event message_timer;
|
||||||
@@ -1433,7 +1408,7 @@ struct key_binding {
|
|||||||
RB_HEAD(key_bindings, key_binding);
|
RB_HEAD(key_bindings, key_binding);
|
||||||
|
|
||||||
struct key_table {
|
struct key_table {
|
||||||
const char *name;
|
const char *name;
|
||||||
struct key_bindings key_bindings;
|
struct key_bindings key_bindings;
|
||||||
|
|
||||||
u_int references;
|
u_int references;
|
||||||
@@ -1454,6 +1429,7 @@ enum options_table_type {
|
|||||||
OPTIONS_TABLE_STYLE,
|
OPTIONS_TABLE_STYLE,
|
||||||
OPTIONS_TABLE_ARRAY,
|
OPTIONS_TABLE_ARRAY,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum options_table_scope {
|
enum options_table_scope {
|
||||||
OPTIONS_TABLE_NONE,
|
OPTIONS_TABLE_NONE,
|
||||||
OPTIONS_TABLE_SERVER,
|
OPTIONS_TABLE_SERVER,
|
||||||
@@ -1580,12 +1556,11 @@ void hooks_add(struct hooks *, const char *, struct cmd_list *);
|
|||||||
void hooks_copy(struct hooks *, struct hooks *);
|
void hooks_copy(struct hooks *, struct hooks *);
|
||||||
void hooks_remove(struct hooks *, const char *);
|
void hooks_remove(struct hooks *, const char *);
|
||||||
struct hook *hooks_find(struct hooks *, const char *);
|
struct hook *hooks_find(struct hooks *, const char *);
|
||||||
void printflike(4, 5) hooks_run(struct hooks *, struct client *,
|
|
||||||
struct cmd_find_state *, const char *, ...);
|
|
||||||
void printflike(4, 5) hooks_insert(struct hooks *, struct cmdq_item *,
|
void printflike(4, 5) hooks_insert(struct hooks *, struct cmdq_item *,
|
||||||
struct cmd_find_state *, const char *, ...);
|
struct cmd_find_state *, const char *, ...);
|
||||||
|
|
||||||
/* notify.c */
|
/* notify.c */
|
||||||
|
void notify_hook(struct cmdq_item *, const char *);
|
||||||
void notify_input(struct window_pane *, struct evbuffer *);
|
void notify_input(struct window_pane *, struct evbuffer *);
|
||||||
void notify_client(const char *, struct client *);
|
void notify_client(const char *, struct client *);
|
||||||
void notify_session(const char *, struct session *);
|
void notify_session(const char *, struct session *);
|
||||||
@@ -1644,7 +1619,7 @@ extern const struct options_table_entry options_table[];
|
|||||||
/* job.c */
|
/* job.c */
|
||||||
extern struct joblist all_jobs;
|
extern struct joblist all_jobs;
|
||||||
struct job *job_run(const char *, struct session *, const char *,
|
struct job *job_run(const char *, struct session *, const char *,
|
||||||
job_update_cb, job_complete_cb, job_free_cb, void *);
|
job_update_cb, job_complete_cb, job_free_cb, void *, int);
|
||||||
void job_free(struct job *);
|
void job_free(struct job *);
|
||||||
void job_died(struct job *, int);
|
void job_died(struct job *, int);
|
||||||
|
|
||||||
@@ -1764,13 +1739,13 @@ long long args_strtonum(struct args *, u_char, long long, long long,
|
|||||||
/* cmd-find.c */
|
/* cmd-find.c */
|
||||||
int cmd_find_target(struct cmd_find_state *, struct cmdq_item *,
|
int cmd_find_target(struct cmd_find_state *, struct cmdq_item *,
|
||||||
const char *, enum cmd_find_type, int);
|
const char *, enum cmd_find_type, int);
|
||||||
|
struct client *cmd_find_best_client(struct session *);
|
||||||
struct client *cmd_find_client(struct cmdq_item *, const char *, int);
|
struct client *cmd_find_client(struct cmdq_item *, const char *, int);
|
||||||
void cmd_find_clear_state(struct cmd_find_state *, int);
|
void cmd_find_clear_state(struct cmd_find_state *, int);
|
||||||
int cmd_find_empty_state(struct cmd_find_state *);
|
int cmd_find_empty_state(struct cmd_find_state *);
|
||||||
int cmd_find_valid_state(struct cmd_find_state *);
|
int cmd_find_valid_state(struct cmd_find_state *);
|
||||||
void cmd_find_copy_state(struct cmd_find_state *,
|
void cmd_find_copy_state(struct cmd_find_state *,
|
||||||
struct cmd_find_state *);
|
struct cmd_find_state *);
|
||||||
void cmd_find_log_state(const char *, struct cmd_find_state *);
|
|
||||||
void cmd_find_from_session(struct cmd_find_state *,
|
void cmd_find_from_session(struct cmd_find_state *,
|
||||||
struct session *, int);
|
struct session *, int);
|
||||||
void cmd_find_from_winlink(struct cmd_find_state *,
|
void cmd_find_from_winlink(struct cmd_find_state *,
|
||||||
@@ -1790,6 +1765,7 @@ int cmd_find_from_mouse(struct cmd_find_state *,
|
|||||||
int cmd_find_from_nothing(struct cmd_find_state *, int);
|
int cmd_find_from_nothing(struct cmd_find_state *, int);
|
||||||
|
|
||||||
/* cmd.c */
|
/* cmd.c */
|
||||||
|
void cmd_log_argv(int, char **, const char *);
|
||||||
int cmd_pack_argv(int, char **, char *, size_t);
|
int cmd_pack_argv(int, char **, char *, size_t);
|
||||||
int cmd_unpack_argv(char *, size_t, int, char ***);
|
int cmd_unpack_argv(char *, size_t, int, char ***);
|
||||||
char **cmd_copy_argv(int, char **);
|
char **cmd_copy_argv(int, char **);
|
||||||
@@ -1839,13 +1815,13 @@ void cmd_wait_for_flush(void);
|
|||||||
int client_main(struct event_base *, int, char **, int);
|
int client_main(struct event_base *, int, char **, int);
|
||||||
|
|
||||||
/* key-bindings.c */
|
/* key-bindings.c */
|
||||||
RB_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp);
|
|
||||||
RB_PROTOTYPE(key_tables, key_table, entry, key_table_cmp);
|
|
||||||
extern struct key_tables key_tables;
|
|
||||||
int key_table_cmp(struct key_table *, struct key_table *);
|
|
||||||
int key_bindings_cmp(struct key_binding *, struct key_binding *);
|
|
||||||
struct key_table *key_bindings_get_table(const char *, int);
|
struct key_table *key_bindings_get_table(const char *, int);
|
||||||
|
struct key_table *key_bindings_first_table(void);
|
||||||
|
struct key_table *key_bindings_next_table(struct key_table *);
|
||||||
void key_bindings_unref_table(struct key_table *);
|
void key_bindings_unref_table(struct key_table *);
|
||||||
|
struct key_binding *key_bindings_get(struct key_table *, key_code);
|
||||||
|
struct key_binding *key_bindings_first(struct key_table *);
|
||||||
|
struct key_binding *key_bindings_next(struct key_table *, struct key_binding *);
|
||||||
void key_bindings_add(const char *, key_code, int, struct cmd_list *);
|
void key_bindings_add(const char *, key_code, int, struct cmd_list *);
|
||||||
void key_bindings_remove(const char *, key_code);
|
void key_bindings_remove(const char *, key_code);
|
||||||
void key_bindings_remove_table(const char *);
|
void key_bindings_remove_table(const char *);
|
||||||
@@ -1879,12 +1855,11 @@ void server_add_accept(int);
|
|||||||
/* server-client.c */
|
/* server-client.c */
|
||||||
u_int server_client_how_many(void);
|
u_int server_client_how_many(void);
|
||||||
void server_client_set_identify(struct client *, u_int);
|
void server_client_set_identify(struct client *, u_int);
|
||||||
void server_client_clear_identify(struct client *, struct window_pane *);
|
|
||||||
void server_client_set_key_table(struct client *, const char *);
|
void server_client_set_key_table(struct client *, const char *);
|
||||||
const char *server_client_get_key_table(struct client *);
|
const char *server_client_get_key_table(struct client *);
|
||||||
int server_client_check_nested(struct client *);
|
int server_client_check_nested(struct client *);
|
||||||
void server_client_handle_key(struct client *, key_code);
|
void server_client_handle_key(struct client *, key_code);
|
||||||
void server_client_create(int);
|
struct client *server_client_create(int);
|
||||||
int server_client_open(struct client *, char **);
|
int server_client_open(struct client *, char **);
|
||||||
void server_client_unref(struct client *);
|
void server_client_unref(struct client *);
|
||||||
void server_client_lost(struct client *);
|
void server_client_lost(struct client *);
|
||||||
@@ -1897,7 +1872,7 @@ void server_client_push_stderr(struct client *);
|
|||||||
void printflike(2, 3) server_client_add_message(struct client *, const char *,
|
void printflike(2, 3) server_client_add_message(struct client *, const char *,
|
||||||
...);
|
...);
|
||||||
char *server_client_get_path(struct client *, const char *);
|
char *server_client_get_path(struct client *, const char *);
|
||||||
const char *server_client_get_cwd(struct client *);
|
const char *server_client_get_cwd(struct client *, struct session *);
|
||||||
|
|
||||||
/* server-fn.c */
|
/* server-fn.c */
|
||||||
void server_redraw_client(struct client *);
|
void server_redraw_client(struct client *);
|
||||||
@@ -1912,6 +1887,7 @@ void server_status_window(struct window *);
|
|||||||
void server_lock(void);
|
void server_lock(void);
|
||||||
void server_lock_session(struct session *);
|
void server_lock_session(struct session *);
|
||||||
void server_lock_client(struct client *);
|
void server_lock_client(struct client *);
|
||||||
|
void server_kill_pane(struct window_pane *);
|
||||||
void server_kill_window(struct window *);
|
void server_kill_window(struct window *);
|
||||||
int server_link_window(struct session *,
|
int server_link_window(struct session *,
|
||||||
struct winlink *, struct session *, int, int, int, char **);
|
struct winlink *, struct session *, int, int, int, char **);
|
||||||
@@ -1928,6 +1904,7 @@ void status_timer_start(struct client *);
|
|||||||
void status_timer_start_all(void);
|
void status_timer_start_all(void);
|
||||||
void status_update_saved(struct session *s);
|
void status_update_saved(struct session *s);
|
||||||
int status_at_line(struct client *);
|
int status_at_line(struct client *);
|
||||||
|
u_int status_line_size(struct session *);
|
||||||
struct window *status_get_window_at(struct client *, u_int);
|
struct window *status_get_window_at(struct client *, u_int);
|
||||||
int status_redraw(struct client *);
|
int status_redraw(struct client *);
|
||||||
void printflike(2, 3) status_message_set(struct client *, const char *, ...);
|
void printflike(2, 3) status_message_set(struct client *, const char *, ...);
|
||||||
@@ -1994,7 +1971,9 @@ char *grid_string_cells(struct grid *, u_int, u_int, u_int,
|
|||||||
struct grid_cell **, int, int, int);
|
struct grid_cell **, int, int, int);
|
||||||
void grid_duplicate_lines(struct grid *, u_int, struct grid *, u_int,
|
void grid_duplicate_lines(struct grid *, u_int, struct grid *, u_int,
|
||||||
u_int);
|
u_int);
|
||||||
u_int grid_reflow(struct grid *, struct grid *, u_int);
|
void grid_reflow(struct grid *, u_int, u_int *);
|
||||||
|
struct grid_line *grid_get_line(struct grid *, u_int);
|
||||||
|
void grid_adjust_lines(struct grid *, u_int);
|
||||||
|
|
||||||
/* grid-view.c */
|
/* grid-view.c */
|
||||||
void grid_view_get_cell(struct grid *, u_int, u_int, struct grid_cell *);
|
void grid_view_get_cell(struct grid *, u_int, u_int, struct grid_cell *);
|
||||||
@@ -2035,6 +2014,8 @@ void screen_write_putc(struct screen_write_ctx *, const struct grid_cell *,
|
|||||||
u_char);
|
u_char);
|
||||||
void screen_write_copy(struct screen_write_ctx *, struct screen *, u_int,
|
void screen_write_copy(struct screen_write_ctx *, struct screen *, u_int,
|
||||||
u_int, u_int, u_int, bitstr_t *, const struct grid_cell *);
|
u_int, u_int, u_int, bitstr_t *, const struct grid_cell *);
|
||||||
|
void screen_write_fast_copy(struct screen_write_ctx *, struct screen *,
|
||||||
|
u_int, u_int, u_int, u_int);
|
||||||
void screen_write_hline(struct screen_write_ctx *, u_int, int, int);
|
void screen_write_hline(struct screen_write_ctx *, u_int, int, int);
|
||||||
void screen_write_vline(struct screen_write_ctx *, u_int, int, int);
|
void screen_write_vline(struct screen_write_ctx *, u_int, int, int);
|
||||||
void screen_write_box(struct screen_write_ctx *, u_int, u_int);
|
void screen_write_box(struct screen_write_ctx *, u_int, u_int);
|
||||||
@@ -2086,9 +2067,11 @@ void screen_reset_tabs(struct screen *);
|
|||||||
void screen_set_cursor_style(struct screen *, u_int);
|
void screen_set_cursor_style(struct screen *, u_int);
|
||||||
void screen_set_cursor_colour(struct screen *, const char *);
|
void screen_set_cursor_colour(struct screen *, const char *);
|
||||||
void screen_set_title(struct screen *, const char *);
|
void screen_set_title(struct screen *, const char *);
|
||||||
|
void screen_push_title(struct screen *);
|
||||||
|
void screen_pop_title(struct screen *);
|
||||||
void screen_resize(struct screen *, u_int, u_int, int);
|
void screen_resize(struct screen *, u_int, u_int, int);
|
||||||
void screen_set_selection(struct screen *,
|
void screen_set_selection(struct screen *, u_int, u_int, u_int, u_int,
|
||||||
u_int, u_int, u_int, u_int, u_int, struct grid_cell *);
|
u_int, int, struct grid_cell *);
|
||||||
void screen_clear_selection(struct screen *);
|
void screen_clear_selection(struct screen *);
|
||||||
void screen_hide_selection(struct screen *);
|
void screen_hide_selection(struct screen *);
|
||||||
int screen_check_selection(struct screen *, u_int, u_int);
|
int screen_check_selection(struct screen *, u_int, u_int);
|
||||||
@@ -2132,7 +2115,7 @@ int window_has_pane(struct window *, struct window_pane *);
|
|||||||
int window_set_active_pane(struct window *, struct window_pane *);
|
int window_set_active_pane(struct window *, struct window_pane *);
|
||||||
void window_redraw_active_switch(struct window *,
|
void window_redraw_active_switch(struct window *,
|
||||||
struct window_pane *);
|
struct window_pane *);
|
||||||
struct window_pane *window_add_pane(struct window *, struct window_pane *,
|
struct window_pane *window_add_pane(struct window *, struct window_pane *, int,
|
||||||
int, u_int);
|
int, u_int);
|
||||||
void window_resize(struct window *, u_int, u_int);
|
void window_resize(struct window *, u_int, u_int);
|
||||||
int window_zoom(struct window_pane *);
|
int window_zoom(struct window_pane *);
|
||||||
@@ -2188,6 +2171,9 @@ void layout_free_cell(struct layout_cell *);
|
|||||||
void layout_print_cell(struct layout_cell *, const char *, u_int);
|
void layout_print_cell(struct layout_cell *, const char *, u_int);
|
||||||
void layout_destroy_cell(struct window *, struct layout_cell *,
|
void layout_destroy_cell(struct window *, struct layout_cell *,
|
||||||
struct layout_cell **);
|
struct layout_cell **);
|
||||||
|
void layout_resize_layout(struct window *, struct layout_cell *,
|
||||||
|
enum layout_type, int, int);
|
||||||
|
struct layout_cell *layout_search_by_border(struct layout_cell *, u_int, u_int);
|
||||||
void layout_set_size(struct layout_cell *, u_int, u_int, u_int,
|
void layout_set_size(struct layout_cell *, u_int, u_int, u_int,
|
||||||
u_int);
|
u_int);
|
||||||
void layout_make_leaf(struct layout_cell *, struct window_pane *);
|
void layout_make_leaf(struct layout_cell *, struct window_pane *);
|
||||||
@@ -2207,6 +2193,8 @@ void layout_assign_pane(struct layout_cell *, struct window_pane *);
|
|||||||
struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type,
|
struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type,
|
||||||
int, int, int);
|
int, int, int);
|
||||||
void layout_close_pane(struct window_pane *);
|
void layout_close_pane(struct window_pane *);
|
||||||
|
int layout_spread_cell(struct window *, struct layout_cell *);
|
||||||
|
void layout_spread_out(struct window_pane *);
|
||||||
|
|
||||||
/* layout-custom.c */
|
/* layout-custom.c */
|
||||||
char *layout_dump(struct layout_cell *);
|
char *layout_dump(struct layout_cell *);
|
||||||
@@ -2219,17 +2207,22 @@ u_int layout_set_next(struct window *);
|
|||||||
u_int layout_set_previous(struct window *);
|
u_int layout_set_previous(struct window *);
|
||||||
|
|
||||||
/* mode-tree.c */
|
/* mode-tree.c */
|
||||||
|
typedef void (*mode_tree_build_cb)(void *, u_int, uint64_t *, const char *);
|
||||||
|
typedef void (*mode_tree_draw_cb)(void *, void *, struct screen_write_ctx *,
|
||||||
|
u_int, u_int);
|
||||||
|
typedef int (*mode_tree_search_cb)(void *, void *, const char *);
|
||||||
|
typedef void (*mode_tree_each_cb)(void *, void *, struct client *, key_code);
|
||||||
u_int mode_tree_count_tagged(struct mode_tree_data *);
|
u_int mode_tree_count_tagged(struct mode_tree_data *);
|
||||||
void *mode_tree_get_current(struct mode_tree_data *);
|
void *mode_tree_get_current(struct mode_tree_data *);
|
||||||
void mode_tree_each_tagged(struct mode_tree_data *, void (*)(void *, void *,
|
void mode_tree_expand_current(struct mode_tree_data *);
|
||||||
key_code), key_code, int);
|
void mode_tree_set_current(struct mode_tree_data *, uint64_t);
|
||||||
void mode_tree_up(struct mode_tree_data *, int);
|
void mode_tree_each_tagged(struct mode_tree_data *, mode_tree_each_cb,
|
||||||
|
struct client *, key_code, int);
|
||||||
void mode_tree_down(struct mode_tree_data *, int);
|
void mode_tree_down(struct mode_tree_data *, int);
|
||||||
struct mode_tree_data *mode_tree_start(struct window_pane *, struct args *,
|
struct mode_tree_data *mode_tree_start(struct window_pane *, struct args *,
|
||||||
void (*)(void *, u_int, uint64_t *, const char *),
|
mode_tree_build_cb, mode_tree_draw_cb, mode_tree_search_cb,
|
||||||
struct screen *(*)(void *, void *, u_int, u_int),
|
void *, const char **, u_int, struct screen **);
|
||||||
int (*)(void *, void *, const char *), void *, const char **,
|
void mode_tree_zoom(struct mode_tree_data *, struct args *);
|
||||||
u_int, struct screen **);
|
|
||||||
void mode_tree_build(struct mode_tree_data *);
|
void mode_tree_build(struct mode_tree_data *);
|
||||||
void mode_tree_free(struct mode_tree_data *);
|
void mode_tree_free(struct mode_tree_data *);
|
||||||
void mode_tree_resize(struct mode_tree_data *, u_int, u_int);
|
void mode_tree_resize(struct mode_tree_data *, u_int, u_int);
|
||||||
@@ -2239,7 +2232,7 @@ struct mode_tree_item *mode_tree_add(struct mode_tree_data *,
|
|||||||
void mode_tree_remove(struct mode_tree_data *, struct mode_tree_item *);
|
void mode_tree_remove(struct mode_tree_data *, struct mode_tree_item *);
|
||||||
void mode_tree_draw(struct mode_tree_data *);
|
void mode_tree_draw(struct mode_tree_data *);
|
||||||
int mode_tree_key(struct mode_tree_data *, struct client *, key_code *,
|
int mode_tree_key(struct mode_tree_data *, struct client *, key_code *,
|
||||||
struct mouse_event *);
|
struct mouse_event *, u_int *, u_int *);
|
||||||
void mode_tree_run_command(struct client *, struct cmd_find_state *,
|
void mode_tree_run_command(struct client *, struct cmd_find_state *,
|
||||||
const char *, const char *);
|
const char *, const char *);
|
||||||
|
|
||||||
@@ -2294,11 +2287,8 @@ void control_notify_session_window_changed(struct session *);
|
|||||||
|
|
||||||
/* session.c */
|
/* session.c */
|
||||||
extern struct sessions sessions;
|
extern struct sessions sessions;
|
||||||
extern struct session_groups session_groups;
|
|
||||||
int session_cmp(struct session *, struct session *);
|
int session_cmp(struct session *, struct session *);
|
||||||
RB_PROTOTYPE(sessions, session, entry, session_cmp);
|
RB_PROTOTYPE(sessions, session, entry, session_cmp);
|
||||||
int session_group_cmp(struct session_group *, struct session_group *);
|
|
||||||
RB_PROTOTYPE(session_groups, session_group, entry, session_group_cmp);
|
|
||||||
int session_alive(struct session *);
|
int session_alive(struct session *);
|
||||||
struct session *session_find(const char *);
|
struct session *session_find(const char *);
|
||||||
struct session *session_find_by_id_str(const char *);
|
struct session *session_find_by_id_str(const char *);
|
||||||
@@ -2331,6 +2321,7 @@ struct session_group *session_group_new(const char *);
|
|||||||
void session_group_add(struct session_group *, struct session *);
|
void session_group_add(struct session_group *, struct session *);
|
||||||
void session_group_synchronize_to(struct session *);
|
void session_group_synchronize_to(struct session *);
|
||||||
void session_group_synchronize_from(struct session *);
|
void session_group_synchronize_from(struct session *);
|
||||||
|
u_int session_group_count(struct session_group *);
|
||||||
void session_renumber_windows(struct session *);
|
void session_renumber_windows(struct session *);
|
||||||
|
|
||||||
/* utf8.c */
|
/* utf8.c */
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ then
|
|||||||
else
|
else
|
||||||
SEQ=seq
|
SEQ=seq
|
||||||
fi
|
fi
|
||||||
SEPARATOR=';'
|
SEPARATOR=':'
|
||||||
|
|
||||||
setBackgroundColor()
|
setBackgroundColor()
|
||||||
{
|
{
|
||||||
|
|||||||
116
tty-keys.c
116
tty-keys.c
@@ -171,7 +171,12 @@ static const struct tty_default_key_raw tty_default_raw_keys[] = {
|
|||||||
{ "\033[201~", KEYC_PASTE_END },
|
{ "\033[201~", KEYC_PASTE_END },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Default terminfo(5) keys. */
|
/*
|
||||||
|
* Default terminfo(5) keys. Any keys that have builtin modifiers
|
||||||
|
* (that is, where the key itself contains the modifiers) has the
|
||||||
|
* KEYC_XTERM flag set so a leading escape is not treated as meta (and
|
||||||
|
* probably removed).
|
||||||
|
*/
|
||||||
struct tty_default_key_code {
|
struct tty_default_key_code {
|
||||||
enum tty_code_code code;
|
enum tty_code_code code;
|
||||||
key_code key;
|
key_code key;
|
||||||
@@ -191,61 +196,61 @@ static const struct tty_default_key_code tty_default_code_keys[] = {
|
|||||||
{ TTYC_KF11, KEYC_F11 },
|
{ TTYC_KF11, KEYC_F11 },
|
||||||
{ TTYC_KF12, KEYC_F12 },
|
{ TTYC_KF12, KEYC_F12 },
|
||||||
|
|
||||||
{ TTYC_KF13, KEYC_F1|KEYC_SHIFT },
|
{ TTYC_KF13, KEYC_F1|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF14, KEYC_F2|KEYC_SHIFT },
|
{ TTYC_KF14, KEYC_F2|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF15, KEYC_F3|KEYC_SHIFT },
|
{ TTYC_KF15, KEYC_F3|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF16, KEYC_F4|KEYC_SHIFT },
|
{ TTYC_KF16, KEYC_F4|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF17, KEYC_F5|KEYC_SHIFT },
|
{ TTYC_KF17, KEYC_F5|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF18, KEYC_F6|KEYC_SHIFT },
|
{ TTYC_KF18, KEYC_F6|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF19, KEYC_F7|KEYC_SHIFT },
|
{ TTYC_KF19, KEYC_F7|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF20, KEYC_F8|KEYC_SHIFT },
|
{ TTYC_KF20, KEYC_F8|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF21, KEYC_F9|KEYC_SHIFT },
|
{ TTYC_KF21, KEYC_F9|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF22, KEYC_F10|KEYC_SHIFT },
|
{ TTYC_KF22, KEYC_F10|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF23, KEYC_F11|KEYC_SHIFT },
|
{ TTYC_KF23, KEYC_F11|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF24, KEYC_F12|KEYC_SHIFT },
|
{ TTYC_KF24, KEYC_F12|KEYC_SHIFT|KEYC_XTERM },
|
||||||
|
|
||||||
{ TTYC_KF25, KEYC_F1|KEYC_CTRL },
|
{ TTYC_KF25, KEYC_F1|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF26, KEYC_F2|KEYC_CTRL },
|
{ TTYC_KF26, KEYC_F2|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF27, KEYC_F3|KEYC_CTRL },
|
{ TTYC_KF27, KEYC_F3|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF28, KEYC_F4|KEYC_CTRL },
|
{ TTYC_KF28, KEYC_F4|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF29, KEYC_F5|KEYC_CTRL },
|
{ TTYC_KF29, KEYC_F5|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF30, KEYC_F6|KEYC_CTRL },
|
{ TTYC_KF30, KEYC_F6|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF31, KEYC_F7|KEYC_CTRL },
|
{ TTYC_KF31, KEYC_F7|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF32, KEYC_F8|KEYC_CTRL },
|
{ TTYC_KF32, KEYC_F8|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF33, KEYC_F9|KEYC_CTRL },
|
{ TTYC_KF33, KEYC_F9|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF34, KEYC_F10|KEYC_CTRL },
|
{ TTYC_KF34, KEYC_F10|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF35, KEYC_F11|KEYC_CTRL },
|
{ TTYC_KF35, KEYC_F11|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF36, KEYC_F12|KEYC_CTRL },
|
{ TTYC_KF36, KEYC_F12|KEYC_CTRL|KEYC_XTERM },
|
||||||
|
|
||||||
{ TTYC_KF37, KEYC_F1|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF37, KEYC_F1|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF38, KEYC_F2|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF38, KEYC_F2|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF39, KEYC_F3|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF39, KEYC_F3|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF40, KEYC_F4|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF40, KEYC_F4|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF41, KEYC_F5|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF41, KEYC_F5|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF42, KEYC_F6|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF42, KEYC_F6|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF43, KEYC_F7|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF43, KEYC_F7|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF44, KEYC_F8|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF44, KEYC_F8|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF45, KEYC_F9|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF45, KEYC_F9|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF46, KEYC_F10|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF46, KEYC_F10|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF47, KEYC_F11|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF47, KEYC_F11|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KF48, KEYC_F12|KEYC_SHIFT|KEYC_CTRL },
|
{ TTYC_KF48, KEYC_F12|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
|
|
||||||
{ TTYC_KF49, KEYC_F1|KEYC_ESCAPE },
|
{ TTYC_KF49, KEYC_F1|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF50, KEYC_F2|KEYC_ESCAPE },
|
{ TTYC_KF50, KEYC_F2|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF51, KEYC_F3|KEYC_ESCAPE },
|
{ TTYC_KF51, KEYC_F3|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF52, KEYC_F4|KEYC_ESCAPE },
|
{ TTYC_KF52, KEYC_F4|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF53, KEYC_F5|KEYC_ESCAPE },
|
{ TTYC_KF53, KEYC_F5|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF54, KEYC_F6|KEYC_ESCAPE },
|
{ TTYC_KF54, KEYC_F6|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF55, KEYC_F7|KEYC_ESCAPE },
|
{ TTYC_KF55, KEYC_F7|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF56, KEYC_F8|KEYC_ESCAPE },
|
{ TTYC_KF56, KEYC_F8|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF57, KEYC_F9|KEYC_ESCAPE },
|
{ TTYC_KF57, KEYC_F9|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF58, KEYC_F10|KEYC_ESCAPE },
|
{ TTYC_KF58, KEYC_F10|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF59, KEYC_F11|KEYC_ESCAPE },
|
{ TTYC_KF59, KEYC_F11|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KF60, KEYC_F12|KEYC_ESCAPE },
|
{ TTYC_KF60, KEYC_F12|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
|
|
||||||
{ TTYC_KF61, KEYC_F1|KEYC_ESCAPE|KEYC_SHIFT },
|
{ TTYC_KF61, KEYC_F1|KEYC_ESCAPE|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF62, KEYC_F2|KEYC_ESCAPE|KEYC_SHIFT },
|
{ TTYC_KF62, KEYC_F2|KEYC_ESCAPE|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KF63, KEYC_F3|KEYC_ESCAPE|KEYC_SHIFT },
|
{ TTYC_KF63, KEYC_F3|KEYC_ESCAPE|KEYC_SHIFT|KEYC_XTERM },
|
||||||
|
|
||||||
{ TTYC_KICH1, KEYC_IC },
|
{ TTYC_KICH1, KEYC_IC },
|
||||||
{ TTYC_KDCH1, KEYC_DC },
|
{ TTYC_KDCH1, KEYC_DC },
|
||||||
@@ -261,17 +266,14 @@ static const struct tty_default_key_code tty_default_code_keys[] = {
|
|||||||
{ TTYC_KCUB1, KEYC_LEFT },
|
{ TTYC_KCUB1, KEYC_LEFT },
|
||||||
{ TTYC_KCUF1, KEYC_RIGHT },
|
{ TTYC_KCUF1, KEYC_RIGHT },
|
||||||
|
|
||||||
/*
|
/* Key and modifier capabilities. */
|
||||||
* Key and modifier capabilities. We set the xterm flag to mark that
|
|
||||||
* any leading escape means an escape key press and not the modifier.
|
|
||||||
*/
|
|
||||||
{ TTYC_KDC2, KEYC_DC|KEYC_SHIFT|KEYC_XTERM },
|
{ TTYC_KDC2, KEYC_DC|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KDC3, KEYC_DC|KEYC_ESCAPE|KEYC_XTERM },
|
{ TTYC_KDC3, KEYC_DC|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KDC4, KEYC_DC|KEYC_SHIFT|KEYC_ESCAPE|KEYC_XTERM },
|
{ TTYC_KDC4, KEYC_DC|KEYC_SHIFT|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KDC5, KEYC_DC|KEYC_CTRL|KEYC_XTERM },
|
{ TTYC_KDC5, KEYC_DC|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KDC6, KEYC_DC|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
{ TTYC_KDC6, KEYC_DC|KEYC_SHIFT|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KDC7, KEYC_DC|KEYC_ESCAPE|KEYC_CTRL|KEYC_XTERM },
|
{ TTYC_KDC7, KEYC_DC|KEYC_ESCAPE|KEYC_CTRL|KEYC_XTERM },
|
||||||
{ TTYC_KIND, KEYC_UP|KEYC_SHIFT|KEYC_XTERM },
|
{ TTYC_KIND, KEYC_DOWN|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KDN2, KEYC_DOWN|KEYC_SHIFT|KEYC_XTERM },
|
{ TTYC_KDN2, KEYC_DOWN|KEYC_SHIFT|KEYC_XTERM },
|
||||||
{ TTYC_KDN3, KEYC_DOWN|KEYC_ESCAPE|KEYC_XTERM },
|
{ TTYC_KDN3, KEYC_DOWN|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
{ TTYC_KDN4, KEYC_DOWN|KEYC_SHIFT|KEYC_ESCAPE|KEYC_XTERM },
|
{ TTYC_KDN4, KEYC_DOWN|KEYC_SHIFT|KEYC_ESCAPE|KEYC_XTERM },
|
||||||
|
|||||||
13
tty-term.c
13
tty-term.c
@@ -240,6 +240,7 @@ static const struct tty_term_code_entry tty_term_codes[] = {
|
|||||||
[TTYC_MS] = { TTYCODE_STRING, "Ms" },
|
[TTYC_MS] = { TTYCODE_STRING, "Ms" },
|
||||||
[TTYC_OP] = { TTYCODE_STRING, "op" },
|
[TTYC_OP] = { TTYCODE_STRING, "op" },
|
||||||
[TTYC_REV] = { TTYCODE_STRING, "rev" },
|
[TTYC_REV] = { TTYCODE_STRING, "rev" },
|
||||||
|
[TTYC_RGB] = { TTYCODE_FLAG, "RGB" },
|
||||||
[TTYC_RI] = { TTYCODE_STRING, "ri" },
|
[TTYC_RI] = { TTYCODE_STRING, "ri" },
|
||||||
[TTYC_RMACS] = { TTYCODE_STRING, "rmacs" },
|
[TTYC_RMACS] = { TTYCODE_STRING, "rmacs" },
|
||||||
[TTYC_RMCUP] = { TTYCODE_STRING, "rmcup" },
|
[TTYC_RMCUP] = { TTYCODE_STRING, "rmcup" },
|
||||||
@@ -493,8 +494,9 @@ tty_term_find(char *name, int fd, char **cause)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Figure out if we have 256. */
|
/* Figure out if we have 256 colours (or more). */
|
||||||
if (tty_term_number(term, TTYC_COLORS) == 256)
|
if (tty_term_number(term, TTYC_COLORS) >= 256 ||
|
||||||
|
tty_term_has(term, TTYC_RGB))
|
||||||
term->flags |= TERM_256COLOURS;
|
term->flags |= TERM_256COLOURS;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -531,8 +533,11 @@ tty_term_find(char *name, int fd, char **cause)
|
|||||||
code->type = TTYCODE_STRING;
|
code->type = TTYCODE_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* On terminals with RGB colour (TC), fill in setrgbf and setrgbb. */
|
/*
|
||||||
if (tty_term_flag(term, TTYC_TC) &&
|
* On terminals with RGB colour (Tc or RGB), fill in setrgbf and
|
||||||
|
* setrgbb if they are missing.
|
||||||
|
*/
|
||||||
|
if ((tty_term_flag(term, TTYC_TC) || tty_term_flag(term, TTYC_RGB)) &&
|
||||||
!tty_term_has(term, TTYC_SETRGBF) &&
|
!tty_term_has(term, TTYC_SETRGBF) &&
|
||||||
!tty_term_has(term, TTYC_SETRGBB)) {
|
!tty_term_has(term, TTYC_SETRGBB)) {
|
||||||
code = &term->codes[TTYC_SETRGBF];
|
code = &term->codes[TTYC_SETRGBF];
|
||||||
|
|||||||
157
tty.c
157
tty.c
@@ -878,15 +878,42 @@ tty_draw_pane(struct tty *tty, const struct window_pane *wp, u_int py, u_int ox,
|
|||||||
tty_draw_line(tty, wp, wp->screen, py, ox, oy);
|
tty_draw_line(tty, wp, wp->screen, py, ox, oy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct grid_cell *
|
||||||
|
tty_check_codeset(struct tty *tty, const struct grid_cell *gc)
|
||||||
|
{
|
||||||
|
static struct grid_cell new;
|
||||||
|
u_int n;
|
||||||
|
|
||||||
|
/* Characters less than 0x7f are always fine, no matter what. */
|
||||||
|
if (gc->data.size == 1 && *gc->data.data < 0x7f)
|
||||||
|
return (gc);
|
||||||
|
|
||||||
|
/* UTF-8 terminal and a UTF-8 character - fine. */
|
||||||
|
if (tty->flags & TTY_UTF8)
|
||||||
|
return (gc);
|
||||||
|
|
||||||
|
/* Replace by the right number of underscores. */
|
||||||
|
n = gc->data.width;
|
||||||
|
if (n > UTF8_SIZE)
|
||||||
|
n = UTF8_SIZE;
|
||||||
|
memcpy(&new, gc, sizeof new);
|
||||||
|
new.data.size = n;
|
||||||
|
memset(new.data.data, '_', n);
|
||||||
|
return (&new);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_draw_line(struct tty *tty, const struct window_pane *wp,
|
tty_draw_line(struct tty *tty, const struct window_pane *wp,
|
||||||
struct screen *s, u_int py, u_int ox, u_int oy)
|
struct screen *s, u_int py, u_int ox, u_int oy)
|
||||||
{
|
{
|
||||||
|
struct grid *gd = s->grid;
|
||||||
struct grid_cell gc, last;
|
struct grid_cell gc, last;
|
||||||
|
const struct grid_cell *gcp;
|
||||||
u_int i, j, ux, sx, nx, width;
|
u_int i, j, ux, sx, nx, width;
|
||||||
int flags, cleared = 0;
|
int flags, cleared = 0;
|
||||||
char buf[512];
|
char buf[512];
|
||||||
size_t len, old_len;
|
size_t len, old_len;
|
||||||
|
u_int cellsize;
|
||||||
|
|
||||||
flags = (tty->flags & TTY_NOCURSOR);
|
flags = (tty->flags & TTY_NOCURSOR);
|
||||||
tty->flags |= TTY_NOCURSOR;
|
tty->flags |= TTY_NOCURSOR;
|
||||||
@@ -900,15 +927,17 @@ tty_draw_line(struct tty *tty, const struct window_pane *wp,
|
|||||||
* there may be empty background cells after it (from BCE).
|
* there may be empty background cells after it (from BCE).
|
||||||
*/
|
*/
|
||||||
sx = screen_size_x(s);
|
sx = screen_size_x(s);
|
||||||
if (sx > s->grid->linedata[s->grid->hsize + py].cellsize)
|
|
||||||
sx = s->grid->linedata[s->grid->hsize + py].cellsize;
|
cellsize = grid_get_line(gd, gd->hsize + py)->cellsize;
|
||||||
|
if (sx > cellsize)
|
||||||
|
sx = cellsize;
|
||||||
if (sx > tty->sx)
|
if (sx > tty->sx)
|
||||||
sx = tty->sx;
|
sx = tty->sx;
|
||||||
ux = 0;
|
ux = 0;
|
||||||
|
|
||||||
if (wp == NULL ||
|
if (wp == NULL ||
|
||||||
py == 0 ||
|
py == 0 ||
|
||||||
(~s->grid->linedata[s->grid->hsize + py - 1].flags & GRID_LINE_WRAPPED) ||
|
(~grid_get_line(gd, gd->hsize + py - 1)->flags & GRID_LINE_WRAPPED) ||
|
||||||
ox != 0 ||
|
ox != 0 ||
|
||||||
tty->cx < tty->sx ||
|
tty->cx < tty->sx ||
|
||||||
screen_size_x(s) < tty->sx) {
|
screen_size_x(s) < tty->sx) {
|
||||||
@@ -932,18 +961,16 @@ tty_draw_line(struct tty *tty, const struct window_pane *wp,
|
|||||||
width = 0;
|
width = 0;
|
||||||
|
|
||||||
for (i = 0; i < sx; i++) {
|
for (i = 0; i < sx; i++) {
|
||||||
grid_view_get_cell(s->grid, i, py, &gc);
|
grid_view_get_cell(gd, i, py, &gc);
|
||||||
|
gcp = tty_check_codeset(tty, &gc);
|
||||||
if (len != 0 &&
|
if (len != 0 &&
|
||||||
(((~tty->flags & TTY_UTF8) &&
|
((gcp->attr & GRID_ATTR_CHARSET) ||
|
||||||
(gc.data.size != 1 ||
|
gcp->flags != last.flags ||
|
||||||
*gc.data.data >= 0x7f ||
|
gcp->attr != last.attr ||
|
||||||
gc.data.width != 1)) ||
|
gcp->fg != last.fg ||
|
||||||
(gc.attr & GRID_ATTR_CHARSET) ||
|
gcp->bg != last.bg ||
|
||||||
gc.flags != last.flags ||
|
ux + width + gcp->data.width >= screen_size_x(s) ||
|
||||||
gc.attr != last.attr ||
|
(sizeof buf) - len < gcp->data.size)) {
|
||||||
gc.fg != last.fg ||
|
|
||||||
gc.bg != last.bg ||
|
|
||||||
(sizeof buf) - len < gc.data.size)) {
|
|
||||||
tty_attributes(tty, &last, wp);
|
tty_attributes(tty, &last, wp);
|
||||||
tty_putn(tty, buf, len, width);
|
tty_putn(tty, buf, len, width);
|
||||||
ux += width;
|
ux += width;
|
||||||
@@ -952,28 +979,27 @@ tty_draw_line(struct tty *tty, const struct window_pane *wp,
|
|||||||
width = 0;
|
width = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gc.flags & GRID_FLAG_SELECTED)
|
if (gcp->flags & GRID_FLAG_SELECTED)
|
||||||
screen_select_cell(s, &last, &gc);
|
screen_select_cell(s, &last, gcp);
|
||||||
else
|
else
|
||||||
memcpy(&last, &gc, sizeof last);
|
memcpy(&last, gcp, sizeof last);
|
||||||
if (((~tty->flags & TTY_UTF8) &&
|
if (ux + gcp->data.width > screen_size_x(s)) {
|
||||||
(gc.data.size != 1 ||
|
|
||||||
*gc.data.data >= 0x7f ||
|
|
||||||
gc.data.width != 1)) ||
|
|
||||||
(gc.attr & GRID_ATTR_CHARSET)) {
|
|
||||||
tty_attributes(tty, &last, wp);
|
tty_attributes(tty, &last, wp);
|
||||||
if (~tty->flags & TTY_UTF8) {
|
for (j = 0; j < gcp->data.width; j++) {
|
||||||
for (j = 0; j < gc.data.width; j++)
|
if (ux + j > screen_size_x(s))
|
||||||
tty_putc(tty, '_');
|
break;
|
||||||
} else {
|
tty_putc(tty, ' ');
|
||||||
for (j = 0; j < gc.data.size; j++)
|
ux++;
|
||||||
tty_putc(tty, gc.data.data[j]);
|
|
||||||
}
|
}
|
||||||
|
} else if (gcp->attr & GRID_ATTR_CHARSET) {
|
||||||
|
tty_attributes(tty, &last, wp);
|
||||||
|
for (j = 0; j < gcp->data.size; j++)
|
||||||
|
tty_putc(tty, gcp->data.data[j]);
|
||||||
ux += gc.data.width;
|
ux += gc.data.width;
|
||||||
} else {
|
} else {
|
||||||
memcpy(buf + len, gc.data.data, gc.data.size);
|
memcpy(buf + len, gcp->data.data, gcp->data.size);
|
||||||
len += gc.data.size;
|
len += gcp->data.size;
|
||||||
width += gc.data.width;
|
width += gcp->data.width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (len != 0) {
|
if (len != 0) {
|
||||||
@@ -993,8 +1019,8 @@ tty_draw_line(struct tty *tty, const struct window_pane *wp,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nx = screen_size_x(s) - ux;
|
if (!cleared && ux < screen_size_x(s)) {
|
||||||
if (!cleared && ux < tty->sx && nx != 0) {
|
nx = screen_size_x(s) - ux;
|
||||||
tty_default_attributes(tty, wp, 8);
|
tty_default_attributes(tty, wp, 8);
|
||||||
tty_clear_line(tty, wp, oy + py, ox + ux, nx, 8);
|
tty_clear_line(tty, wp, oy + py, ox + ux, nx, 8);
|
||||||
}
|
}
|
||||||
@@ -1038,7 +1064,7 @@ tty_write(void (*cmdfn)(struct tty *, const struct tty_ctx *),
|
|||||||
ctx->xoff = wp->xoff;
|
ctx->xoff = wp->xoff;
|
||||||
ctx->yoff = wp->yoff;
|
ctx->yoff = wp->yoff;
|
||||||
if (status_at_line(c) == 0)
|
if (status_at_line(c) == 0)
|
||||||
ctx->yoff++;
|
ctx->yoff += status_line_size(c->session);
|
||||||
|
|
||||||
cmdfn(&c->tty, ctx);
|
cmdfn(&c->tty, ctx);
|
||||||
}
|
}
|
||||||
@@ -1221,13 +1247,18 @@ tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx)
|
|||||||
tty_margin_pane(tty, ctx);
|
tty_margin_pane(tty, ctx);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we want to wrap a pane, the cursor needs to be exactly on the
|
* If we want to wrap a pane while using margins, the cursor needs to
|
||||||
* right of the region. But if the pane isn't on the right, it may be
|
* be exactly on the right of the region. If the cursor is entirely off
|
||||||
* off the edge - if so, move the cursor back to the right.
|
* the edge - move it back to the right. Some terminals are funny about
|
||||||
|
* this and insert extra spaces, so only use the right if margins are
|
||||||
|
* enabled.
|
||||||
*/
|
*/
|
||||||
if (ctx->xoff + ctx->ocx > tty->rright)
|
if (ctx->xoff + ctx->ocx > tty->rright) {
|
||||||
tty_cursor(tty, tty->rright, ctx->yoff + ctx->ocy);
|
if (!tty_use_margin(tty))
|
||||||
else
|
tty_cursor(tty, 0, ctx->yoff + ctx->ocy);
|
||||||
|
else
|
||||||
|
tty_cursor(tty, tty->rright, ctx->yoff + ctx->ocy);
|
||||||
|
} else
|
||||||
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
||||||
|
|
||||||
tty_putc(tty, '\n');
|
tty_putc(tty, '\n');
|
||||||
@@ -1252,11 +1283,16 @@ tty_cmd_scrollup(struct tty *tty, const struct tty_ctx *ctx)
|
|||||||
tty_margin_pane(tty, ctx);
|
tty_margin_pane(tty, ctx);
|
||||||
|
|
||||||
if (ctx->num == 1 || !tty_term_has(tty->term, TTYC_INDN)) {
|
if (ctx->num == 1 || !tty_term_has(tty->term, TTYC_INDN)) {
|
||||||
tty_cursor(tty, tty->rright, tty->rlower);
|
if (!tty_use_margin(tty))
|
||||||
|
tty_cursor(tty, 0, tty->rlower);
|
||||||
|
else
|
||||||
|
tty_cursor(tty, tty->rright, tty->rlower);
|
||||||
for (i = 0; i < ctx->num; i++)
|
for (i = 0; i < ctx->num; i++)
|
||||||
tty_putc(tty, '\n');
|
tty_putc(tty, '\n');
|
||||||
} else
|
} else {
|
||||||
|
tty_cursor(tty, 0, tty->cy);
|
||||||
tty_putcode1(tty, TTYC_INDN, ctx->num);
|
tty_putcode1(tty, TTYC_INDN, ctx->num);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1400,7 +1436,7 @@ static void
|
|||||||
tty_cell(struct tty *tty, const struct grid_cell *gc,
|
tty_cell(struct tty *tty, const struct grid_cell *gc,
|
||||||
const struct window_pane *wp)
|
const struct window_pane *wp)
|
||||||
{
|
{
|
||||||
u_int i;
|
const struct grid_cell *gcp;
|
||||||
|
|
||||||
/* Skip last character if terminal is stupid. */
|
/* Skip last character if terminal is stupid. */
|
||||||
if ((tty->term->flags & TERM_EARLYWRAP) &&
|
if ((tty->term->flags & TERM_EARLYWRAP) &&
|
||||||
@@ -1416,22 +1452,16 @@ tty_cell(struct tty *tty, const struct grid_cell *gc,
|
|||||||
tty_attributes(tty, gc, wp);
|
tty_attributes(tty, gc, wp);
|
||||||
|
|
||||||
/* Get the cell and if ASCII write with putc to do ACS translation. */
|
/* Get the cell and if ASCII write with putc to do ACS translation. */
|
||||||
if (gc->data.size == 1) {
|
gcp = tty_check_codeset(tty, gc);
|
||||||
if (*gc->data.data < 0x20 || *gc->data.data == 0x7f)
|
if (gcp->data.size == 1) {
|
||||||
|
if (*gcp->data.data < 0x20 || *gcp->data.data == 0x7f)
|
||||||
return;
|
return;
|
||||||
tty_putc(tty, *gc->data.data);
|
tty_putc(tty, *gcp->data.data);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If not UTF-8, write _. */
|
|
||||||
if (!(tty->flags & TTY_UTF8)) {
|
|
||||||
for (i = 0; i < gc->data.width; i++)
|
|
||||||
tty_putc(tty, '_');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the data. */
|
/* Write the data. */
|
||||||
tty_putn(tty, gc->data.data, gc->data.size, gc->data.width);
|
tty_putn(tty, gcp->data.data, gcp->data.size, gcp->data.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1973,8 +2003,7 @@ tty_colours_fg(struct tty *tty, const struct grid_cell *gc)
|
|||||||
char s[32];
|
char s[32];
|
||||||
|
|
||||||
/* Is this a 24-bit or 256-colour colour? */
|
/* Is this a 24-bit or 256-colour colour? */
|
||||||
if (gc->fg & COLOUR_FLAG_RGB ||
|
if (gc->fg & COLOUR_FLAG_RGB || gc->fg & COLOUR_FLAG_256) {
|
||||||
gc->fg & COLOUR_FLAG_256) {
|
|
||||||
if (tty_try_colour(tty, gc->fg, "38") == 0)
|
if (tty_try_colour(tty, gc->fg, "38") == 0)
|
||||||
goto save_fg;
|
goto save_fg;
|
||||||
/* Should not get here, already converted in tty_check_fg. */
|
/* Should not get here, already converted in tty_check_fg. */
|
||||||
@@ -2003,8 +2032,7 @@ tty_colours_bg(struct tty *tty, const struct grid_cell *gc)
|
|||||||
char s[32];
|
char s[32];
|
||||||
|
|
||||||
/* Is this a 24-bit or 256-colour colour? */
|
/* Is this a 24-bit or 256-colour colour? */
|
||||||
if (gc->bg & COLOUR_FLAG_RGB ||
|
if (gc->bg & COLOUR_FLAG_RGB || gc->bg & COLOUR_FLAG_256) {
|
||||||
gc->bg & COLOUR_FLAG_256) {
|
|
||||||
if (tty_try_colour(tty, gc->bg, "48") == 0)
|
if (tty_try_colour(tty, gc->bg, "48") == 0)
|
||||||
goto save_bg;
|
goto save_bg;
|
||||||
/* Should not get here, already converted in tty_check_bg. */
|
/* Should not get here, already converted in tty_check_bg. */
|
||||||
@@ -2034,11 +2062,15 @@ tty_try_colour(struct tty *tty, int colour, const char *type)
|
|||||||
|
|
||||||
if (colour & COLOUR_FLAG_256) {
|
if (colour & COLOUR_FLAG_256) {
|
||||||
/*
|
/*
|
||||||
* If the user has specified -2 to the client, setaf and setab
|
* If the user has specified -2 to the client (meaning
|
||||||
* may not work (or they may not want to use them), so send the
|
* TERM_256COLOURS is set), setaf and setab may not work (or
|
||||||
* usual sequence.
|
* they may not want to use them), so send the usual sequence.
|
||||||
|
*
|
||||||
|
* Also if RGB is set, setaf and setab do not support the 256
|
||||||
|
* colour palette so use the sequences directly there too.
|
||||||
*/
|
*/
|
||||||
if (tty->term_flags & TERM_256COLOURS)
|
if ((tty->term_flags & TERM_256COLOURS) ||
|
||||||
|
tty_term_has(tty->term, TTYC_RGB))
|
||||||
goto fallback_256;
|
goto fallback_256;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2079,6 +2111,7 @@ tty_try_colour(struct tty *tty, int colour, const char *type)
|
|||||||
|
|
||||||
fallback_256:
|
fallback_256:
|
||||||
xsnprintf(s, sizeof s, "\033[%s;5;%dm", type, colour & 0xff);
|
xsnprintf(s, sizeof s, "\033[%s;5;%dm", type, colour & 0xff);
|
||||||
|
log_debug("%s: 256 colour fallback: %s", tty->client->name, s);
|
||||||
tty_puts(tty, s);
|
tty_puts(tty, s);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,26 +195,20 @@ window_buffer_build(void *modedata, u_int sort_type, __unused uint64_t *tag,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct screen *
|
static void
|
||||||
window_buffer_draw(__unused void *modedata, void *itemdata, u_int sx, u_int sy)
|
window_buffer_draw(__unused void *modedata, void *itemdata,
|
||||||
|
struct screen_write_ctx *ctx, u_int sx, u_int sy)
|
||||||
{
|
{
|
||||||
struct window_buffer_itemdata *item = itemdata;
|
struct window_buffer_itemdata *item = itemdata;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
static struct screen s;
|
|
||||||
struct screen_write_ctx ctx;
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
const char *pdata, *end, *cp;
|
const char *pdata, *end, *cp;
|
||||||
size_t psize, at;
|
size_t psize, at;
|
||||||
u_int i;
|
u_int i, cx = ctx->s->cx, cy = ctx->s->cy;
|
||||||
|
|
||||||
pb = paste_get_name(item->name);
|
pb = paste_get_name(item->name);
|
||||||
if (pb == NULL)
|
if (pb == NULL)
|
||||||
return (NULL);
|
return;
|
||||||
|
|
||||||
screen_init(&s, sx, sy, 0);
|
|
||||||
|
|
||||||
screen_write_start(&ctx, NULL, &s);
|
|
||||||
screen_write_clearscreen(&ctx, 8);
|
|
||||||
|
|
||||||
pdata = end = paste_buffer_data(pb, &psize);
|
pdata = end = paste_buffer_data(pb, &psize);
|
||||||
for (i = 0; i < sy; i++) {
|
for (i = 0; i < sy; i++) {
|
||||||
@@ -231,17 +225,14 @@ window_buffer_draw(__unused void *modedata, void *itemdata, u_int sx, u_int sy)
|
|||||||
line[at] = '\0';
|
line[at] = '\0';
|
||||||
|
|
||||||
if (*line != '\0') {
|
if (*line != '\0') {
|
||||||
screen_write_cursormove(&ctx, 0, i);
|
screen_write_cursormove(ctx, cx, cy + i);
|
||||||
screen_write_puts(&ctx, &grid_default_cell, "%s", line);
|
screen_write_puts(ctx, &grid_default_cell, "%s", line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end == pdata + psize)
|
if (end == pdata + psize)
|
||||||
break;
|
break;
|
||||||
end++;
|
end++;
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_write_stop(&ctx);
|
|
||||||
return (&s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -281,6 +272,7 @@ window_buffer_init(struct window_pane *wp, __unused struct cmd_find_state *fs,
|
|||||||
data->data = mode_tree_start(wp, args, window_buffer_build,
|
data->data = mode_tree_start(wp, args, window_buffer_build,
|
||||||
window_buffer_draw, window_buffer_search, data,
|
window_buffer_draw, window_buffer_search, data,
|
||||||
window_buffer_sort_list, nitems(window_buffer_sort_list), &s);
|
window_buffer_sort_list, nitems(window_buffer_sort_list), &s);
|
||||||
|
mode_tree_zoom(data->data, args);
|
||||||
|
|
||||||
mode_tree_build(data->data);
|
mode_tree_build(data->data);
|
||||||
mode_tree_draw(data->data);
|
mode_tree_draw(data->data);
|
||||||
@@ -318,7 +310,8 @@ window_buffer_resize(struct window_pane *wp, u_int sx, u_int sy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_buffer_do_delete(void* modedata, void *itemdata, __unused key_code key)
|
window_buffer_do_delete(void* modedata, void *itemdata,
|
||||||
|
__unused struct client *c, __unused key_code key)
|
||||||
{
|
{
|
||||||
struct window_buffer_modedata *data = modedata;
|
struct window_buffer_modedata *data = modedata;
|
||||||
struct window_buffer_itemdata *item = itemdata;
|
struct window_buffer_itemdata *item = itemdata;
|
||||||
@@ -330,53 +323,53 @@ window_buffer_do_delete(void* modedata, void *itemdata, __unused key_code key)
|
|||||||
paste_free(pb);
|
paste_free(pb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
window_buffer_do_paste(void* modedata, void *itemdata, struct client *c,
|
||||||
|
__unused key_code key)
|
||||||
|
{
|
||||||
|
struct window_buffer_modedata *data = modedata;
|
||||||
|
struct window_buffer_itemdata *item = itemdata;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
|
||||||
|
if ((pb = paste_get_name(item->name)) != NULL)
|
||||||
|
mode_tree_run_command(c, NULL, data->command, item->name);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_buffer_key(struct window_pane *wp, struct client *c,
|
window_buffer_key(struct window_pane *wp, struct client *c,
|
||||||
__unused struct session *s, key_code key, struct mouse_event *m)
|
__unused struct session *s, key_code key, struct mouse_event *m)
|
||||||
{
|
{
|
||||||
struct window_buffer_modedata *data = wp->modedata;
|
struct window_buffer_modedata *data = wp->modedata;
|
||||||
|
struct mode_tree_data *mtd = data->data;
|
||||||
struct window_buffer_itemdata *item;
|
struct window_buffer_itemdata *item;
|
||||||
char *command, *name;
|
|
||||||
int finished;
|
int finished;
|
||||||
|
|
||||||
/*
|
finished = mode_tree_key(mtd, c, &key, m, NULL, NULL);
|
||||||
* t = toggle tag
|
|
||||||
* T = tag none
|
|
||||||
* C-t = tag all
|
|
||||||
* q = exit
|
|
||||||
* O = change sort order
|
|
||||||
*
|
|
||||||
* d = delete buffer
|
|
||||||
* D = delete tagged buffers
|
|
||||||
* Enter = paste buffer
|
|
||||||
*/
|
|
||||||
|
|
||||||
finished = mode_tree_key(data->data, c, &key, m);
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'd':
|
case 'd':
|
||||||
item = mode_tree_get_current(data->data);
|
item = mode_tree_get_current(mtd);
|
||||||
window_buffer_do_delete(data, item, key);
|
window_buffer_do_delete(data, item, c, key);
|
||||||
mode_tree_build(data->data);
|
mode_tree_build(mtd);
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
mode_tree_each_tagged(data->data, window_buffer_do_delete, key,
|
mode_tree_each_tagged(mtd, window_buffer_do_delete, c, key, 0);
|
||||||
0);
|
mode_tree_build(mtd);
|
||||||
mode_tree_build(data->data);
|
|
||||||
break;
|
break;
|
||||||
|
case 'P':
|
||||||
|
mode_tree_each_tagged(mtd, window_buffer_do_paste, c, key, 0);
|
||||||
|
finished = 1;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
case '\r':
|
case '\r':
|
||||||
item = mode_tree_get_current(data->data);
|
item = mode_tree_get_current(mtd);
|
||||||
command = xstrdup(data->command);
|
window_buffer_do_paste(data, item, c, key);
|
||||||
name = xstrdup(item->name);
|
finished = 1;
|
||||||
window_pane_reset_mode(wp);
|
break;
|
||||||
mode_tree_run_command(c, NULL, command, name);
|
|
||||||
free(name);
|
|
||||||
free(command);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (finished || paste_get_top(NULL) == NULL)
|
if (finished || paste_get_top(NULL) == NULL)
|
||||||
window_pane_reset_mode(wp);
|
window_pane_reset_mode(wp);
|
||||||
else {
|
else {
|
||||||
mode_tree_draw(data->data);
|
mode_tree_draw(mtd);
|
||||||
wp->flags |= PANE_REDRAW;
|
wp->flags |= PANE_REDRAW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,37 +210,29 @@ window_client_build(void *modedata, u_int sort_type, __unused uint64_t *tag,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct screen *
|
static void
|
||||||
window_client_draw(__unused void *modedata, void *itemdata, u_int sx, u_int sy)
|
window_client_draw(__unused void *modedata, void *itemdata,
|
||||||
|
struct screen_write_ctx *ctx, u_int sx, u_int sy)
|
||||||
{
|
{
|
||||||
struct window_client_itemdata *item = itemdata;
|
struct window_client_itemdata *item = itemdata;
|
||||||
struct client *c = item->c;
|
struct client *c = item->c;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
static struct screen s;
|
u_int cx = ctx->s->cx, cy = ctx->s->cy;
|
||||||
struct screen_write_ctx ctx;
|
|
||||||
|
|
||||||
if (c->session == NULL || (c->flags & (CLIENT_DEAD|CLIENT_DETACHING)))
|
if (c->session == NULL || (c->flags & (CLIENT_DEAD|CLIENT_DETACHING)))
|
||||||
return (NULL);
|
return;
|
||||||
wp = c->session->curw->window->active;
|
wp = c->session->curw->window->active;
|
||||||
|
|
||||||
screen_init(&s, sx, sy, 0);
|
screen_write_preview(ctx, &wp->base, sx, sy - 3);
|
||||||
|
|
||||||
screen_write_start(&ctx, NULL, &s);
|
screen_write_cursormove(ctx, cx, cy + sy - 2);
|
||||||
screen_write_clearscreen(&ctx, 8);
|
screen_write_hline(ctx, sx, 0, 0);
|
||||||
|
|
||||||
screen_write_preview(&ctx, &wp->base, sx, sy - 3);
|
screen_write_cursormove(ctx, cx, cy + sy - 1);
|
||||||
|
if (c->status.old_status != NULL)
|
||||||
screen_write_cursormove(&ctx, 0, sy - 2);
|
screen_write_fast_copy(ctx, c->status.old_status, 0, 0, sx, 1);
|
||||||
screen_write_hline(&ctx, sx, 0, 0);
|
|
||||||
|
|
||||||
screen_write_cursormove(&ctx, 0, sy - 1);
|
|
||||||
if (c->old_status != NULL)
|
|
||||||
screen_write_copy(&ctx, c->old_status, 0, 0, sx, 1, NULL, NULL);
|
|
||||||
else
|
else
|
||||||
screen_write_copy(&ctx, &c->status, 0, 0, sx, 1, NULL, NULL);
|
screen_write_fast_copy(ctx, &c->status.status, 0, 0, sx, 1);
|
||||||
|
|
||||||
screen_write_stop(&ctx);
|
|
||||||
return (&s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct screen *
|
static struct screen *
|
||||||
@@ -264,6 +256,7 @@ window_client_init(struct window_pane *wp, __unused struct cmd_find_state *fs,
|
|||||||
data->data = mode_tree_start(wp, args, window_client_build,
|
data->data = mode_tree_start(wp, args, window_client_build,
|
||||||
window_client_draw, NULL, data, window_client_sort_list,
|
window_client_draw, NULL, data, window_client_sort_list,
|
||||||
nitems(window_client_sort_list), &s);
|
nitems(window_client_sort_list), &s);
|
||||||
|
mode_tree_zoom(data->data, args);
|
||||||
|
|
||||||
mode_tree_build(data->data);
|
mode_tree_build(data->data);
|
||||||
mode_tree_draw(data->data);
|
mode_tree_draw(data->data);
|
||||||
@@ -301,7 +294,8 @@ window_client_resize(struct window_pane *wp, u_int sx, u_int sy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_client_do_detach(void* modedata, void *itemdata, key_code key)
|
window_client_do_detach(void* modedata, void *itemdata,
|
||||||
|
__unused struct client *c, key_code key)
|
||||||
{
|
{
|
||||||
struct window_client_modedata *data = modedata;
|
struct window_client_modedata *data = modedata;
|
||||||
struct window_client_itemdata *item = itemdata;
|
struct window_client_itemdata *item = itemdata;
|
||||||
@@ -321,56 +315,35 @@ window_client_key(struct window_pane *wp, struct client *c,
|
|||||||
__unused struct session *s, key_code key, struct mouse_event *m)
|
__unused struct session *s, key_code key, struct mouse_event *m)
|
||||||
{
|
{
|
||||||
struct window_client_modedata *data = wp->modedata;
|
struct window_client_modedata *data = wp->modedata;
|
||||||
|
struct mode_tree_data *mtd = data->data;
|
||||||
struct window_client_itemdata *item;
|
struct window_client_itemdata *item;
|
||||||
char *command, *name;
|
|
||||||
int finished;
|
int finished;
|
||||||
|
|
||||||
/*
|
finished = mode_tree_key(mtd, c, &key, m, NULL, NULL);
|
||||||
* t = toggle tag
|
|
||||||
* T = tag none
|
|
||||||
* C-t = tag all
|
|
||||||
* q = exit
|
|
||||||
* O = change sort order
|
|
||||||
*
|
|
||||||
* d = detach client
|
|
||||||
* D = detach tagged clients
|
|
||||||
* x = detach and kill client
|
|
||||||
* X = detach and kill tagged clients
|
|
||||||
* z = suspend client
|
|
||||||
* Z = suspend tagged clients
|
|
||||||
* Enter = detach client
|
|
||||||
*/
|
|
||||||
|
|
||||||
finished = mode_tree_key(data->data, c, &key, m);
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'x':
|
case 'x':
|
||||||
case 'z':
|
case 'z':
|
||||||
item = mode_tree_get_current(data->data);
|
item = mode_tree_get_current(mtd);
|
||||||
window_client_do_detach(data, item, key);
|
window_client_do_detach(data, item, c, key);
|
||||||
mode_tree_build(data->data);
|
mode_tree_build(mtd);
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
case 'X':
|
case 'X':
|
||||||
case 'Z':
|
case 'Z':
|
||||||
mode_tree_each_tagged(data->data, window_client_do_detach, key,
|
mode_tree_each_tagged(mtd, window_client_do_detach, c, key, 0);
|
||||||
0);
|
mode_tree_build(mtd);
|
||||||
mode_tree_build(data->data);
|
|
||||||
break;
|
break;
|
||||||
case '\r':
|
case '\r':
|
||||||
item = mode_tree_get_current(data->data);
|
item = mode_tree_get_current(mtd);
|
||||||
command = xstrdup(data->command);
|
mode_tree_run_command(c, NULL, data->command, item->c->ttyname);
|
||||||
name = xstrdup(item->c->ttyname);
|
finished = 1;
|
||||||
window_pane_reset_mode(wp);
|
break;
|
||||||
mode_tree_run_command(c, NULL, command, name);
|
|
||||||
free(name);
|
|
||||||
free(command);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (finished || server_client_how_many() == 0)
|
if (finished || server_client_how_many() == 0)
|
||||||
window_pane_reset_mode(wp);
|
window_pane_reset_mode(wp);
|
||||||
else {
|
else {
|
||||||
mode_tree_draw(data->data);
|
mode_tree_draw(mtd);
|
||||||
wp->flags |= PANE_REDRAW;
|
wp->flags |= PANE_REDRAW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
290
window-copy.c
290
window-copy.c
@@ -30,7 +30,7 @@ static void window_copy_command(struct window_pane *, struct client *,
|
|||||||
static struct screen *window_copy_init(struct window_pane *,
|
static struct screen *window_copy_init(struct window_pane *,
|
||||||
struct cmd_find_state *, struct args *);
|
struct cmd_find_state *, struct args *);
|
||||||
static void window_copy_free(struct window_pane *);
|
static void window_copy_free(struct window_pane *);
|
||||||
static int window_copy_pagedown(struct window_pane *, int);
|
static int window_copy_pagedown(struct window_pane *, int, int);
|
||||||
static void window_copy_next_paragraph(struct window_pane *);
|
static void window_copy_next_paragraph(struct window_pane *);
|
||||||
static void window_copy_previous_paragraph(struct window_pane *);
|
static void window_copy_previous_paragraph(struct window_pane *);
|
||||||
static void window_copy_resize(struct window_pane *, u_int, u_int);
|
static void window_copy_resize(struct window_pane *, u_int, u_int);
|
||||||
@@ -57,16 +57,17 @@ static void window_copy_move_right(struct screen *, u_int *, u_int *);
|
|||||||
static int window_copy_is_lowercase(const char *);
|
static int window_copy_is_lowercase(const char *);
|
||||||
static int window_copy_search_jump(struct window_pane *, struct grid *,
|
static int window_copy_search_jump(struct window_pane *, struct grid *,
|
||||||
struct grid *, u_int, u_int, u_int, int, int, int);
|
struct grid *, u_int, u_int, u_int, int, int, int);
|
||||||
static int window_copy_search(struct window_pane *, int, int);
|
static int window_copy_search(struct window_pane *, int);
|
||||||
static int window_copy_search_up(struct window_pane *, int);
|
static int window_copy_search_up(struct window_pane *);
|
||||||
static int window_copy_search_down(struct window_pane *, int);
|
static int window_copy_search_down(struct window_pane *);
|
||||||
static void window_copy_goto_line(struct window_pane *, const char *);
|
static void window_copy_goto_line(struct window_pane *, const char *);
|
||||||
static void window_copy_update_cursor(struct window_pane *, u_int, u_int);
|
static void window_copy_update_cursor(struct window_pane *, u_int, u_int);
|
||||||
static void window_copy_start_selection(struct window_pane *);
|
static void window_copy_start_selection(struct window_pane *);
|
||||||
static int window_copy_adjust_selection(struct window_pane *, u_int *,
|
static int window_copy_adjust_selection(struct window_pane *, u_int *,
|
||||||
u_int *);
|
u_int *);
|
||||||
|
static int window_copy_set_selection(struct window_pane *, int);
|
||||||
static int window_copy_update_selection(struct window_pane *, int);
|
static int window_copy_update_selection(struct window_pane *, int);
|
||||||
static void window_copy_synchronize_cursor(struct window_pane *wp);
|
static void window_copy_synchronize_cursor(struct window_pane *);
|
||||||
static void *window_copy_get_selection(struct window_pane *, size_t *);
|
static void *window_copy_get_selection(struct window_pane *, size_t *);
|
||||||
static void window_copy_copy_buffer(struct window_pane *, const char *,
|
static void window_copy_copy_buffer(struct window_pane *, const char *,
|
||||||
void *, size_t);
|
void *, size_t);
|
||||||
@@ -91,8 +92,8 @@ static void window_copy_cursor_up(struct window_pane *, int);
|
|||||||
static void window_copy_cursor_down(struct window_pane *, int);
|
static void window_copy_cursor_down(struct window_pane *, int);
|
||||||
static void window_copy_cursor_jump(struct window_pane *);
|
static void window_copy_cursor_jump(struct window_pane *);
|
||||||
static void window_copy_cursor_jump_back(struct window_pane *);
|
static void window_copy_cursor_jump_back(struct window_pane *);
|
||||||
static void window_copy_cursor_jump_to(struct window_pane *, int);
|
static void window_copy_cursor_jump_to(struct window_pane *);
|
||||||
static void window_copy_cursor_jump_to_back(struct window_pane *, int);
|
static void window_copy_cursor_jump_to_back(struct window_pane *);
|
||||||
static void window_copy_cursor_next_word(struct window_pane *,
|
static void window_copy_cursor_next_word(struct window_pane *,
|
||||||
const char *);
|
const char *);
|
||||||
static void window_copy_cursor_next_word_end(struct window_pane *,
|
static void window_copy_cursor_next_word_end(struct window_pane *,
|
||||||
@@ -151,12 +152,12 @@ struct window_copy_mode_data {
|
|||||||
struct screen *backing;
|
struct screen *backing;
|
||||||
int backing_written; /* backing display started */
|
int backing_written; /* backing display started */
|
||||||
|
|
||||||
u_int oy; /* number of lines scrolled up */
|
u_int oy; /* number of lines scrolled up */
|
||||||
|
|
||||||
u_int selx; /* beginning of selection */
|
u_int selx; /* beginning of selection */
|
||||||
u_int sely;
|
u_int sely;
|
||||||
|
|
||||||
u_int endselx; /* end of selection */
|
u_int endselx; /* end of selection */
|
||||||
u_int endsely;
|
u_int endsely;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -165,14 +166,20 @@ struct window_copy_mode_data {
|
|||||||
CURSORDRAG_SEL, /* start is synchronized with cursor */
|
CURSORDRAG_SEL, /* start is synchronized with cursor */
|
||||||
} cursordrag;
|
} cursordrag;
|
||||||
|
|
||||||
|
int modekeys;
|
||||||
|
enum {
|
||||||
|
LINE_SEL_NONE,
|
||||||
|
LINE_SEL_LEFT_RIGHT,
|
||||||
|
LINE_SEL_RIGHT_LEFT,
|
||||||
|
} lineflag; /* line selection mode */
|
||||||
int rectflag; /* in rectangle copy mode? */
|
int rectflag; /* in rectangle copy mode? */
|
||||||
int scroll_exit; /* exit on scroll to end? */
|
int scroll_exit; /* exit on scroll to end? */
|
||||||
|
|
||||||
u_int cx;
|
u_int cx;
|
||||||
u_int cy;
|
u_int cy;
|
||||||
|
|
||||||
u_int lastcx; /* position in last line w/ content */
|
u_int lastcx; /* position in last line w/ content */
|
||||||
u_int lastsx; /* size of last line w/ content */
|
u_int lastsx; /* size of last line w/ content */
|
||||||
|
|
||||||
int searchtype;
|
int searchtype;
|
||||||
char *searchstr;
|
char *searchstr;
|
||||||
@@ -194,21 +201,10 @@ window_copy_init(struct window_pane *wp, __unused struct cmd_find_state *fs,
|
|||||||
struct window_copy_mode_data *data;
|
struct window_copy_mode_data *data;
|
||||||
struct screen *s;
|
struct screen *s;
|
||||||
|
|
||||||
wp->modedata = data = xmalloc(sizeof *data);
|
wp->modedata = data = xcalloc(1, sizeof *data);
|
||||||
|
|
||||||
data->oy = 0;
|
|
||||||
data->cx = 0;
|
|
||||||
data->cy = 0;
|
|
||||||
|
|
||||||
data->cursordrag = CURSORDRAG_NONE;
|
data->cursordrag = CURSORDRAG_NONE;
|
||||||
|
data->lineflag = LINE_SEL_NONE;
|
||||||
data->lastcx = 0;
|
|
||||||
data->lastsx = 0;
|
|
||||||
|
|
||||||
data->backing_written = 0;
|
|
||||||
|
|
||||||
data->rectflag = 0;
|
|
||||||
data->scroll_exit = 0;
|
|
||||||
|
|
||||||
if (wp->searchstr != NULL) {
|
if (wp->searchstr != NULL) {
|
||||||
data->searchtype = WINDOW_COPY_SEARCHUP;
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
||||||
@@ -228,7 +224,7 @@ window_copy_init(struct window_pane *wp, __unused struct cmd_find_state *fs,
|
|||||||
|
|
||||||
s = &data->screen;
|
s = &data->screen;
|
||||||
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
||||||
s->sel.modekeys = options_get_number(wp->window->options, "mode-keys");
|
data->modekeys = options_get_number(wp->window->options, "mode-keys");
|
||||||
|
|
||||||
data->backing = NULL;
|
data->backing = NULL;
|
||||||
|
|
||||||
@@ -357,7 +353,7 @@ window_copy_pageup(struct window_pane *wp, int half_page)
|
|||||||
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
||||||
ox = window_copy_find_length(wp, oy);
|
ox = window_copy_find_length(wp, oy);
|
||||||
|
|
||||||
if (s->sel.lineflag == LINE_SEL_LEFT_RIGHT && oy == data->sely)
|
if (data->lineflag == LINE_SEL_LEFT_RIGHT && oy == data->sely)
|
||||||
window_copy_other_end(wp);
|
window_copy_other_end(wp);
|
||||||
|
|
||||||
if (data->cx != ox) {
|
if (data->cx != ox) {
|
||||||
@@ -379,7 +375,7 @@ window_copy_pageup(struct window_pane *wp, int half_page)
|
|||||||
else
|
else
|
||||||
data->oy += n;
|
data->oy += n;
|
||||||
|
|
||||||
if (!data->screen.sel.flag || !data->rectflag) {
|
if (data->screen.sel == NULL || !data->rectflag) {
|
||||||
py = screen_hsize(data->backing) + data->cy - data->oy;
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
||||||
px = window_copy_find_length(wp, py);
|
px = window_copy_find_length(wp, py);
|
||||||
if ((data->cx >= data->lastsx && data->cx != px) ||
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
||||||
@@ -392,7 +388,7 @@ window_copy_pageup(struct window_pane *wp, int half_page)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
window_copy_pagedown(struct window_pane *wp, int half_page)
|
window_copy_pagedown(struct window_pane *wp, int half_page, int scroll_exit)
|
||||||
{
|
{
|
||||||
struct window_copy_mode_data *data = wp->modedata;
|
struct window_copy_mode_data *data = wp->modedata;
|
||||||
struct screen *s = &data->screen;
|
struct screen *s = &data->screen;
|
||||||
@@ -401,7 +397,7 @@ window_copy_pagedown(struct window_pane *wp, int half_page)
|
|||||||
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
||||||
ox = window_copy_find_length(wp, oy);
|
ox = window_copy_find_length(wp, oy);
|
||||||
|
|
||||||
if (s->sel.lineflag == LINE_SEL_RIGHT_LEFT && oy == data->sely)
|
if (data->lineflag == LINE_SEL_RIGHT_LEFT && oy == data->sely)
|
||||||
window_copy_other_end(wp);
|
window_copy_other_end(wp);
|
||||||
|
|
||||||
if (data->cx != ox) {
|
if (data->cx != ox) {
|
||||||
@@ -423,7 +419,7 @@ window_copy_pagedown(struct window_pane *wp, int half_page)
|
|||||||
else
|
else
|
||||||
data->oy -= n;
|
data->oy -= n;
|
||||||
|
|
||||||
if (!data->screen.sel.flag || !data->rectflag) {
|
if (data->screen.sel == NULL || !data->rectflag) {
|
||||||
py = screen_hsize(data->backing) + data->cy - data->oy;
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
||||||
px = window_copy_find_length(wp, py);
|
px = window_copy_find_length(wp, py);
|
||||||
if ((data->cx >= data->lastsx && data->cx != px) ||
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
||||||
@@ -431,7 +427,7 @@ window_copy_pagedown(struct window_pane *wp, int half_page)
|
|||||||
window_copy_cursor_end_of_line(wp);
|
window_copy_cursor_end_of_line(wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->scroll_exit && data->oy == 0)
|
if (scroll_exit && data->oy == 0)
|
||||||
return (1);
|
return (1);
|
||||||
window_copy_update_selection(wp, 1);
|
window_copy_update_selection(wp, 1);
|
||||||
window_copy_redraw_screen(wp);
|
window_copy_redraw_screen(wp);
|
||||||
@@ -524,7 +520,7 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
struct screen *sn = &data->screen;
|
struct screen *sn = &data->screen;
|
||||||
const char *command, *argument, *ws;
|
const char *command, *argument, *ws;
|
||||||
u_int np = wp->modeprefix;
|
u_int np = wp->modeprefix;
|
||||||
int cancel = 0, redraw = 0;
|
int cancel = 0, redraw = 0, scroll_exit;
|
||||||
char prefix;
|
char prefix;
|
||||||
|
|
||||||
if (args->argc == 0)
|
if (args->argc == 0)
|
||||||
@@ -554,7 +550,7 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
if (m != NULL)
|
if (m != NULL)
|
||||||
window_copy_start_drag(c, m);
|
window_copy_start_drag(c, m);
|
||||||
else {
|
else {
|
||||||
sn->sel.lineflag = LINE_SEL_NONE;
|
data->lineflag = LINE_SEL_NONE;
|
||||||
window_copy_start_selection(wp);
|
window_copy_start_selection(wp);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
@@ -629,9 +625,14 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
}
|
}
|
||||||
if (strcmp(command, "end-of-line") == 0)
|
if (strcmp(command, "end-of-line") == 0)
|
||||||
window_copy_cursor_end_of_line(wp);
|
window_copy_cursor_end_of_line(wp);
|
||||||
if (strcmp(command, "halfpage-down") == 0) {
|
if (strcmp(command, "halfpage-down") == 0 ||
|
||||||
|
strcmp(command, "halfpage-down-and-cancel") == 0) {
|
||||||
|
if (strcmp(command, "halfpage-down-and-cancel") == 0)
|
||||||
|
scroll_exit = 1;
|
||||||
|
else
|
||||||
|
scroll_exit = data->scroll_exit;
|
||||||
for (; np != 0; np--) {
|
for (; np != 0; np--) {
|
||||||
if (window_copy_pagedown(wp, 1)) {
|
if (window_copy_pagedown(wp, 1, scroll_exit)) {
|
||||||
cancel = 1;
|
cancel = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -667,11 +668,11 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
break;
|
break;
|
||||||
case WINDOW_COPY_JUMPTOFORWARD:
|
case WINDOW_COPY_JUMPTOFORWARD:
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_cursor_jump_to(wp, 1);
|
window_copy_cursor_jump_to(wp);
|
||||||
break;
|
break;
|
||||||
case WINDOW_COPY_JUMPTOBACKWARD:
|
case WINDOW_COPY_JUMPTOBACKWARD:
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_cursor_jump_to_back(wp, 1);
|
window_copy_cursor_jump_to_back(wp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,11 +688,11 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
break;
|
break;
|
||||||
case WINDOW_COPY_JUMPTOFORWARD:
|
case WINDOW_COPY_JUMPTOFORWARD:
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_cursor_jump_to_back(wp, 1);
|
window_copy_cursor_jump_to_back(wp);
|
||||||
break;
|
break;
|
||||||
case WINDOW_COPY_JUMPTOBACKWARD:
|
case WINDOW_COPY_JUMPTOBACKWARD:
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_cursor_jump_to(wp, 1);
|
window_copy_cursor_jump_to(wp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -727,9 +728,14 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
if ((np % 2) != 0)
|
if ((np % 2) != 0)
|
||||||
window_copy_other_end(wp);
|
window_copy_other_end(wp);
|
||||||
}
|
}
|
||||||
if (strcmp(command, "page-down") == 0) {
|
if (strcmp(command, "page-down") == 0 ||
|
||||||
|
strcmp(command, "page-down-and-cancel") == 0) {
|
||||||
|
if (strcmp(command, "page-down-and-cancel") == 0)
|
||||||
|
scroll_exit = 1;
|
||||||
|
else
|
||||||
|
scroll_exit = data->scroll_exit;
|
||||||
for (; np != 0; np--) {
|
for (; np != 0; np--) {
|
||||||
if (window_copy_pagedown(wp, 0)) {
|
if (window_copy_pagedown(wp, 0, scroll_exit)) {
|
||||||
cancel = 1;
|
cancel = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -753,13 +759,18 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
window_copy_cursor_previous_word(wp, ws);
|
window_copy_cursor_previous_word(wp, ws);
|
||||||
}
|
}
|
||||||
if (strcmp(command, "rectangle-toggle") == 0) {
|
if (strcmp(command, "rectangle-toggle") == 0) {
|
||||||
sn->sel.lineflag = LINE_SEL_NONE;
|
data->lineflag = LINE_SEL_NONE;
|
||||||
window_copy_rectangle_toggle(wp);
|
window_copy_rectangle_toggle(wp);
|
||||||
}
|
}
|
||||||
if (strcmp(command, "scroll-down") == 0) {
|
if (strcmp(command, "scroll-down") == 0 ||
|
||||||
|
strcmp(command, "scroll-down-and-cancel") == 0) {
|
||||||
|
if (strcmp(command, "scroll-down-and-cancel") == 0)
|
||||||
|
scroll_exit = 1;
|
||||||
|
else
|
||||||
|
scroll_exit = data->scroll_exit;
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_cursor_down(wp, 1);
|
window_copy_cursor_down(wp, 1);
|
||||||
if (data->scroll_exit && data->oy == 0)
|
if (scroll_exit && data->oy == 0)
|
||||||
cancel = 1;
|
cancel = 1;
|
||||||
}
|
}
|
||||||
if (strcmp(command, "scroll-up") == 0) {
|
if (strcmp(command, "scroll-up") == 0) {
|
||||||
@@ -769,23 +780,23 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
if (strcmp(command, "search-again") == 0) {
|
if (strcmp(command, "search-again") == 0) {
|
||||||
if (data->searchtype == WINDOW_COPY_SEARCHUP) {
|
if (data->searchtype == WINDOW_COPY_SEARCHUP) {
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_search_up(wp, 1);
|
window_copy_search_up(wp);
|
||||||
} else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {
|
} else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_search_down(wp, 1);
|
window_copy_search_down(wp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strcmp(command, "search-reverse") == 0) {
|
if (strcmp(command, "search-reverse") == 0) {
|
||||||
if (data->searchtype == WINDOW_COPY_SEARCHUP) {
|
if (data->searchtype == WINDOW_COPY_SEARCHUP) {
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_search_down(wp, 1);
|
window_copy_search_down(wp);
|
||||||
} else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {
|
} else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_search_up(wp, 1);
|
window_copy_search_up(wp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strcmp(command, "select-line") == 0) {
|
if (strcmp(command, "select-line") == 0) {
|
||||||
sn->sel.lineflag = LINE_SEL_LEFT_RIGHT;
|
data->lineflag = LINE_SEL_LEFT_RIGHT;
|
||||||
data->rectflag = 0;
|
data->rectflag = 0;
|
||||||
window_copy_cursor_start_of_line(wp);
|
window_copy_cursor_start_of_line(wp);
|
||||||
window_copy_start_selection(wp);
|
window_copy_start_selection(wp);
|
||||||
@@ -795,7 +806,7 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
if (strcmp(command, "select-word") == 0) {
|
if (strcmp(command, "select-word") == 0) {
|
||||||
sn->sel.lineflag = LINE_SEL_LEFT_RIGHT;
|
data->lineflag = LINE_SEL_LEFT_RIGHT;
|
||||||
data->rectflag = 0;
|
data->rectflag = 0;
|
||||||
ws = options_get_string(s->options, "word-separators");
|
ws = options_get_string(s->options, "word-separators");
|
||||||
window_copy_cursor_previous_word(wp, ws);
|
window_copy_cursor_previous_word(wp, ws);
|
||||||
@@ -841,27 +852,27 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
data->jumptype = WINDOW_COPY_JUMPTOBACKWARD;
|
data->jumptype = WINDOW_COPY_JUMPTOBACKWARD;
|
||||||
data->jumpchar = *argument;
|
data->jumpchar = *argument;
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_cursor_jump_to_back(wp, 1);
|
window_copy_cursor_jump_to_back(wp);
|
||||||
}
|
}
|
||||||
if (strcmp(command, "jump-to-forward") == 0) {
|
if (strcmp(command, "jump-to-forward") == 0) {
|
||||||
data->jumptype = WINDOW_COPY_JUMPTOFORWARD;
|
data->jumptype = WINDOW_COPY_JUMPTOFORWARD;
|
||||||
data->jumpchar = *argument;
|
data->jumpchar = *argument;
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_cursor_jump_to(wp, 1);
|
window_copy_cursor_jump_to(wp);
|
||||||
}
|
}
|
||||||
if (strcmp(command, "search-backward") == 0) {
|
if (strcmp(command, "search-backward") == 0) {
|
||||||
data->searchtype = WINDOW_COPY_SEARCHUP;
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
||||||
free(data->searchstr);
|
free(data->searchstr);
|
||||||
data->searchstr = xstrdup(argument);
|
data->searchstr = xstrdup(argument);
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_search_up(wp, 1);
|
window_copy_search_up(wp);
|
||||||
}
|
}
|
||||||
if (strcmp(command, "search-forward") == 0) {
|
if (strcmp(command, "search-forward") == 0) {
|
||||||
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
||||||
free(data->searchstr);
|
free(data->searchstr);
|
||||||
data->searchstr = xstrdup(argument);
|
data->searchstr = xstrdup(argument);
|
||||||
for (; np != 0; np--)
|
for (; np != 0; np--)
|
||||||
window_copy_search_down(wp, 1);
|
window_copy_search_down(wp);
|
||||||
}
|
}
|
||||||
if (strcmp(command, "search-backward-incremental") == 0) {
|
if (strcmp(command, "search-backward-incremental") == 0) {
|
||||||
prefix = *argument++;
|
prefix = *argument++;
|
||||||
@@ -883,7 +894,7 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
data->searchtype = WINDOW_COPY_SEARCHUP;
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
||||||
free(data->searchstr);
|
free(data->searchstr);
|
||||||
data->searchstr = xstrdup(argument);
|
data->searchstr = xstrdup(argument);
|
||||||
if (!window_copy_search_up(wp, 1)) {
|
if (!window_copy_search_up(wp)) {
|
||||||
window_copy_clear_marks(wp);
|
window_copy_clear_marks(wp);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
@@ -891,7 +902,7 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
||||||
free(data->searchstr);
|
free(data->searchstr);
|
||||||
data->searchstr = xstrdup(argument);
|
data->searchstr = xstrdup(argument);
|
||||||
if (!window_copy_search_down(wp, 1)) {
|
if (!window_copy_search_down(wp)) {
|
||||||
window_copy_clear_marks(wp);
|
window_copy_clear_marks(wp);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
@@ -917,7 +928,7 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
||||||
free(data->searchstr);
|
free(data->searchstr);
|
||||||
data->searchstr = xstrdup(argument);
|
data->searchstr = xstrdup(argument);
|
||||||
if (!window_copy_search_down(wp, 1)) {
|
if (!window_copy_search_down(wp)) {
|
||||||
window_copy_clear_marks(wp);
|
window_copy_clear_marks(wp);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
@@ -925,7 +936,7 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|||||||
data->searchtype = WINDOW_COPY_SEARCHUP;
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
||||||
free(data->searchstr);
|
free(data->searchstr);
|
||||||
data->searchstr = xstrdup(argument);
|
data->searchstr = xstrdup(argument);
|
||||||
if (!window_copy_search_up(wp, 1)) {
|
if (!window_copy_search_up(wp)) {
|
||||||
window_copy_clear_marks(wp);
|
window_copy_clear_marks(wp);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
@@ -955,18 +966,22 @@ window_copy_scroll_to(struct window_pane *wp, u_int px, u_int py)
|
|||||||
|
|
||||||
data->cx = px;
|
data->cx = px;
|
||||||
|
|
||||||
gap = gd->sy / 4;
|
if (py >= gd->hsize - data->oy && py < gd->hsize - data->oy + gd->sy)
|
||||||
if (py < gd->sy) {
|
data->cy = py - (gd->hsize - data->oy);
|
||||||
offset = 0;
|
else {
|
||||||
data->cy = py;
|
gap = gd->sy / 4;
|
||||||
} else if (py > gd->hsize + gd->sy - gap) {
|
if (py < gd->sy) {
|
||||||
offset = gd->hsize;
|
offset = 0;
|
||||||
data->cy = py - gd->hsize;
|
data->cy = py;
|
||||||
} else {
|
} else if (py > gd->hsize + gd->sy - gap) {
|
||||||
offset = py + gap - gd->sy;
|
offset = gd->hsize;
|
||||||
data->cy = py - offset;
|
data->cy = py - gd->hsize;
|
||||||
|
} else {
|
||||||
|
offset = py + gap - gd->sy;
|
||||||
|
data->cy = py - offset;
|
||||||
|
}
|
||||||
|
data->oy = gd->hsize - offset;
|
||||||
}
|
}
|
||||||
data->oy = gd->hsize - offset;
|
|
||||||
|
|
||||||
window_copy_update_selection(wp, 1);
|
window_copy_update_selection(wp, 1);
|
||||||
window_copy_redraw_screen(wp);
|
window_copy_redraw_screen(wp);
|
||||||
@@ -1128,11 +1143,10 @@ window_copy_search_jump(struct window_pane *wp, struct grid *gd,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Search in for text searchstr. If direction is 0 then search up, otherwise
|
* Search in for text searchstr. If direction is 0 then search up, otherwise
|
||||||
* down. If moveflag is 0 then look for string at the current cursor position
|
* down.
|
||||||
* as well.
|
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
window_copy_search(struct window_pane *wp, int direction, int moveflag)
|
window_copy_search(struct window_pane *wp, int direction)
|
||||||
{
|
{
|
||||||
struct window_copy_mode_data *data = wp->modedata;
|
struct window_copy_mode_data *data = wp->modedata;
|
||||||
struct screen *s = data->backing, ss;
|
struct screen *s = data->backing, ss;
|
||||||
@@ -1152,12 +1166,10 @@ window_copy_search(struct window_pane *wp, int direction, int moveflag)
|
|||||||
screen_write_nputs(&ctx, -1, &grid_default_cell, "%s", data->searchstr);
|
screen_write_nputs(&ctx, -1, &grid_default_cell, "%s", data->searchstr);
|
||||||
screen_write_stop(&ctx);
|
screen_write_stop(&ctx);
|
||||||
|
|
||||||
if (moveflag) {
|
if (direction)
|
||||||
if (direction)
|
window_copy_move_right(s, &fx, &fy);
|
||||||
window_copy_move_right(s, &fx, &fy);
|
else
|
||||||
else
|
window_copy_move_left(s, &fx, &fy);
|
||||||
window_copy_move_left(s, &fx, &fy);
|
|
||||||
}
|
|
||||||
window_copy_clear_selection(wp);
|
window_copy_clear_selection(wp);
|
||||||
|
|
||||||
wrapflag = options_get_number(wp->window->options, "wrap-search");
|
wrapflag = options_get_number(wp->window->options, "wrap-search");
|
||||||
@@ -1243,15 +1255,15 @@ window_copy_clear_marks(struct window_pane *wp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
window_copy_search_up(struct window_pane *wp, int moveflag)
|
window_copy_search_up(struct window_pane *wp)
|
||||||
{
|
{
|
||||||
return (window_copy_search(wp, 0, moveflag));
|
return (window_copy_search(wp, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
window_copy_search_down(struct window_pane *wp, int moveflag)
|
window_copy_search_down(struct window_pane *wp)
|
||||||
{
|
{
|
||||||
return (window_copy_search(wp, 1, moveflag));
|
return (window_copy_search(wp, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1418,7 +1430,6 @@ static void
|
|||||||
window_copy_start_selection(struct window_pane *wp)
|
window_copy_start_selection(struct window_pane *wp)
|
||||||
{
|
{
|
||||||
struct window_copy_mode_data *data = wp->modedata;
|
struct window_copy_mode_data *data = wp->modedata;
|
||||||
struct screen *s = &data->screen;
|
|
||||||
|
|
||||||
data->selx = data->cx;
|
data->selx = data->cx;
|
||||||
data->sely = screen_hsize(data->backing) + data->cy - data->oy;
|
data->sely = screen_hsize(data->backing) + data->cy - data->oy;
|
||||||
@@ -1428,8 +1439,7 @@ window_copy_start_selection(struct window_pane *wp)
|
|||||||
|
|
||||||
data->cursordrag = CURSORDRAG_ENDSEL;
|
data->cursordrag = CURSORDRAG_ENDSEL;
|
||||||
|
|
||||||
s->sel.flag = 1;
|
window_copy_set_selection(wp, 1);
|
||||||
window_copy_update_selection(wp, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -1466,6 +1476,17 @@ window_copy_adjust_selection(struct window_pane *wp, u_int *selx, u_int *sely)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
window_copy_update_selection(struct window_pane *wp, int may_redraw)
|
window_copy_update_selection(struct window_pane *wp, int may_redraw)
|
||||||
|
{
|
||||||
|
struct window_copy_mode_data *data = wp->modedata;
|
||||||
|
struct screen *s = &data->screen;
|
||||||
|
|
||||||
|
if (s->sel == NULL && data->lineflag == LINE_SEL_NONE)
|
||||||
|
return (0);
|
||||||
|
return (window_copy_set_selection(wp, may_redraw));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
window_copy_set_selection(struct window_pane *wp, int may_redraw)
|
||||||
{
|
{
|
||||||
struct window_copy_mode_data *data = wp->modedata;
|
struct window_copy_mode_data *data = wp->modedata;
|
||||||
struct screen *s = &data->screen;
|
struct screen *s = &data->screen;
|
||||||
@@ -1474,9 +1495,6 @@ window_copy_update_selection(struct window_pane *wp, int may_redraw)
|
|||||||
u_int sx, sy, cy, endsx, endsy;
|
u_int sx, sy, cy, endsx, endsy;
|
||||||
int startrelpos, endrelpos;
|
int startrelpos, endrelpos;
|
||||||
|
|
||||||
if (!s->sel.flag && s->sel.lineflag == LINE_SEL_NONE)
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
window_copy_synchronize_cursor(wp);
|
window_copy_synchronize_cursor(wp);
|
||||||
|
|
||||||
/* Adjust the selection. */
|
/* Adjust the selection. */
|
||||||
@@ -1499,7 +1517,8 @@ window_copy_update_selection(struct window_pane *wp, int may_redraw)
|
|||||||
/* Set colours and selection. */
|
/* Set colours and selection. */
|
||||||
style_apply(&gc, oo, "mode-style");
|
style_apply(&gc, oo, "mode-style");
|
||||||
gc.flags |= GRID_FLAG_NOPALETTE;
|
gc.flags |= GRID_FLAG_NOPALETTE;
|
||||||
screen_set_selection(s, sx, sy, endsx, endsy, data->rectflag, &gc);
|
screen_set_selection(s, sx, sy, endsx, endsy, data->rectflag,
|
||||||
|
data->modekeys, &gc);
|
||||||
|
|
||||||
if (data->rectflag && may_redraw) {
|
if (data->rectflag && may_redraw) {
|
||||||
/*
|
/*
|
||||||
@@ -1532,10 +1551,10 @@ window_copy_get_selection(struct window_pane *wp, size_t *len)
|
|||||||
char *buf;
|
char *buf;
|
||||||
size_t off;
|
size_t off;
|
||||||
u_int i, xx, yy, sx, sy, ex, ey, ey_last;
|
u_int i, xx, yy, sx, sy, ex, ey, ey_last;
|
||||||
u_int firstsx, lastex, restex, restsx;
|
u_int firstsx, lastex, restex, restsx, selx;
|
||||||
int keys;
|
int keys;
|
||||||
|
|
||||||
if (!s->sel.flag && s->sel.lineflag == LINE_SEL_NONE)
|
if (data->screen.sel == NULL && data->lineflag == LINE_SEL_NONE)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
buf = xmalloc(1);
|
buf = xmalloc(1);
|
||||||
@@ -1583,7 +1602,11 @@ window_copy_get_selection(struct window_pane *wp, size_t *len)
|
|||||||
* Need to ignore the column with the cursor in it, which for
|
* Need to ignore the column with the cursor in it, which for
|
||||||
* rectangular copy means knowing which side the cursor is on.
|
* rectangular copy means knowing which side the cursor is on.
|
||||||
*/
|
*/
|
||||||
if (data->selx < data->cx) {
|
if (data->cursordrag == CURSORDRAG_ENDSEL)
|
||||||
|
selx = data->selx;
|
||||||
|
else
|
||||||
|
selx = data->endselx;
|
||||||
|
if (selx < data->cx) {
|
||||||
/* Selection start is on the left. */
|
/* Selection start is on the left. */
|
||||||
if (keys == MODEKEY_EMACS) {
|
if (keys == MODEKEY_EMACS) {
|
||||||
lastex = data->cx;
|
lastex = data->cx;
|
||||||
@@ -1593,12 +1616,12 @@ window_copy_get_selection(struct window_pane *wp, size_t *len)
|
|||||||
lastex = data->cx + 1;
|
lastex = data->cx + 1;
|
||||||
restex = data->cx + 1;
|
restex = data->cx + 1;
|
||||||
}
|
}
|
||||||
firstsx = data->selx;
|
firstsx = selx;
|
||||||
restsx = data->selx;
|
restsx = selx;
|
||||||
} else {
|
} else {
|
||||||
/* Cursor is on the left. */
|
/* Cursor is on the left. */
|
||||||
lastex = data->selx + 1;
|
lastex = selx + 1;
|
||||||
restex = data->selx + 1;
|
restex = selx + 1;
|
||||||
firstsx = data->cx;
|
firstsx = data->cx;
|
||||||
restsx = data->cx;
|
restsx = data->cx;
|
||||||
}
|
}
|
||||||
@@ -1661,7 +1684,7 @@ window_copy_copy_pipe(struct window_pane *wp, struct session *s,
|
|||||||
return;
|
return;
|
||||||
expanded = format_single(NULL, arg, NULL, s, NULL, wp);
|
expanded = format_single(NULL, arg, NULL, s, NULL, wp);
|
||||||
|
|
||||||
job = job_run(expanded, s, NULL, NULL, NULL, NULL, NULL);
|
job = job_run(expanded, s, NULL, NULL, NULL, NULL, NULL, JOB_NOWAIT);
|
||||||
bufferevent_write(job->event, buf, len);
|
bufferevent_write(job->event, buf, len);
|
||||||
|
|
||||||
free(expanded);
|
free(expanded);
|
||||||
@@ -1735,7 +1758,7 @@ window_copy_copy_line(struct window_pane *wp, char **buf, size_t *off, u_int sy,
|
|||||||
* Work out if the line was wrapped at the screen edge and all of it is
|
* Work out if the line was wrapped at the screen edge and all of it is
|
||||||
* on screen.
|
* on screen.
|
||||||
*/
|
*/
|
||||||
gl = &gd->linedata[sy];
|
gl = grid_get_line(gd, sy);
|
||||||
if (gl->flags & GRID_LINE_WRAPPED && gl->cellsize <= gd->sx)
|
if (gl->flags & GRID_LINE_WRAPPED && gl->cellsize <= gd->sx)
|
||||||
wrapped = 1;
|
wrapped = 1;
|
||||||
|
|
||||||
@@ -1823,7 +1846,7 @@ window_copy_find_length(struct window_pane *wp, u_int py)
|
|||||||
* width of the grid, and screen_write_copy treats them as spaces, so
|
* width of the grid, and screen_write_copy treats them as spaces, so
|
||||||
* ignore them here too.
|
* ignore them here too.
|
||||||
*/
|
*/
|
||||||
px = s->grid->linedata[py].cellsize;
|
px = grid_get_line(s->grid, py)->cellsize;
|
||||||
if (px > screen_size_x(s))
|
if (px > screen_size_x(s))
|
||||||
px = screen_size_x(s);
|
px = screen_size_x(s);
|
||||||
while (px > 0) {
|
while (px > 0) {
|
||||||
@@ -1840,14 +1863,13 @@ window_copy_cursor_start_of_line(struct window_pane *wp)
|
|||||||
{
|
{
|
||||||
struct window_copy_mode_data *data = wp->modedata;
|
struct window_copy_mode_data *data = wp->modedata;
|
||||||
struct screen *back_s = data->backing;
|
struct screen *back_s = data->backing;
|
||||||
struct screen *s = &data->screen;
|
|
||||||
struct grid *gd = back_s->grid;
|
struct grid *gd = back_s->grid;
|
||||||
u_int py;
|
u_int py;
|
||||||
|
|
||||||
if (data->cx == 0 && s->sel.lineflag == LINE_SEL_NONE) {
|
if (data->cx == 0 && data->lineflag == LINE_SEL_NONE) {
|
||||||
py = screen_hsize(back_s) + data->cy - data->oy;
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
||||||
while (py > 0 &&
|
while (py > 0 &&
|
||||||
gd->linedata[py-1].flags & GRID_LINE_WRAPPED) {
|
grid_get_line(gd, py - 1)->flags & GRID_LINE_WRAPPED) {
|
||||||
window_copy_cursor_up(wp, 0);
|
window_copy_cursor_up(wp, 0);
|
||||||
py = screen_hsize(back_s) + data->cy - data->oy;
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
||||||
}
|
}
|
||||||
@@ -1885,22 +1907,24 @@ window_copy_cursor_end_of_line(struct window_pane *wp)
|
|||||||
{
|
{
|
||||||
struct window_copy_mode_data *data = wp->modedata;
|
struct window_copy_mode_data *data = wp->modedata;
|
||||||
struct screen *back_s = data->backing;
|
struct screen *back_s = data->backing;
|
||||||
struct screen *s = &data->screen;
|
|
||||||
struct grid *gd = back_s->grid;
|
struct grid *gd = back_s->grid;
|
||||||
|
struct grid_line *gl;
|
||||||
u_int px, py;
|
u_int px, py;
|
||||||
|
|
||||||
py = screen_hsize(back_s) + data->cy - data->oy;
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
||||||
px = window_copy_find_length(wp, py);
|
px = window_copy_find_length(wp, py);
|
||||||
|
|
||||||
if (data->cx == px && s->sel.lineflag == LINE_SEL_NONE) {
|
if (data->cx == px && data->lineflag == LINE_SEL_NONE) {
|
||||||
if (data->screen.sel.flag && data->rectflag)
|
if (data->screen.sel != NULL && data->rectflag)
|
||||||
px = screen_size_x(back_s);
|
px = screen_size_x(back_s);
|
||||||
if (gd->linedata[py].flags & GRID_LINE_WRAPPED) {
|
gl = grid_get_line(gd, py);
|
||||||
while (py < gd->sy + gd->hsize &&
|
if (gl->flags & GRID_LINE_WRAPPED) {
|
||||||
gd->linedata[py].flags & GRID_LINE_WRAPPED) {
|
while (py < gd->sy + gd->hsize) {
|
||||||
|
gl = grid_get_line(gd, py);
|
||||||
|
if (~gl->flags & GRID_LINE_WRAPPED)
|
||||||
|
break;
|
||||||
window_copy_cursor_down(wp, 0);
|
window_copy_cursor_down(wp, 0);
|
||||||
py = screen_hsize(back_s)
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
||||||
+ data->cy - data->oy;
|
|
||||||
}
|
}
|
||||||
px = window_copy_find_length(wp, py);
|
px = window_copy_find_length(wp, py);
|
||||||
}
|
}
|
||||||
@@ -1918,13 +1942,13 @@ window_copy_other_end(struct window_pane *wp)
|
|||||||
struct screen *s = &data->screen;
|
struct screen *s = &data->screen;
|
||||||
u_int selx, sely, cy, yy, hsize;
|
u_int selx, sely, cy, yy, hsize;
|
||||||
|
|
||||||
if (!s->sel.flag && s->sel.lineflag == LINE_SEL_NONE)
|
if (s->sel == NULL && data->lineflag == LINE_SEL_NONE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (s->sel.lineflag == LINE_SEL_LEFT_RIGHT)
|
if (data->lineflag == LINE_SEL_LEFT_RIGHT)
|
||||||
s->sel.lineflag = LINE_SEL_RIGHT_LEFT;
|
data->lineflag = LINE_SEL_RIGHT_LEFT;
|
||||||
else if (s->sel.lineflag == LINE_SEL_RIGHT_LEFT)
|
else if (data->lineflag == LINE_SEL_RIGHT_LEFT)
|
||||||
s->sel.lineflag = LINE_SEL_LEFT_RIGHT;
|
data->lineflag = LINE_SEL_LEFT_RIGHT;
|
||||||
|
|
||||||
switch (data->cursordrag) {
|
switch (data->cursordrag) {
|
||||||
case CURSORDRAG_NONE:
|
case CURSORDRAG_NONE:
|
||||||
@@ -1996,7 +2020,7 @@ window_copy_cursor_right(struct window_pane *wp)
|
|||||||
|
|
||||||
py = screen_hsize(data->backing) + data->cy - data->oy;
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
||||||
yy = screen_hsize(data->backing) + screen_size_y(data->backing) - 1;
|
yy = screen_hsize(data->backing) + screen_size_y(data->backing) - 1;
|
||||||
if (data->screen.sel.flag && data->rectflag)
|
if (data->screen.sel != NULL && data->rectflag)
|
||||||
px = screen_size_x(&data->screen);
|
px = screen_size_x(&data->screen);
|
||||||
else
|
else
|
||||||
px = window_copy_find_length(wp, py);
|
px = window_copy_find_length(wp, py);
|
||||||
@@ -2033,7 +2057,7 @@ window_copy_cursor_up(struct window_pane *wp, int scroll_only)
|
|||||||
data->lastsx = ox;
|
data->lastsx = ox;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->sel.lineflag == LINE_SEL_LEFT_RIGHT && oy == data->sely)
|
if (data->lineflag == LINE_SEL_LEFT_RIGHT && oy == data->sely)
|
||||||
window_copy_other_end(wp);
|
window_copy_other_end(wp);
|
||||||
|
|
||||||
data->cx = data->lastcx;
|
data->cx = data->lastcx;
|
||||||
@@ -2055,7 +2079,7 @@ window_copy_cursor_up(struct window_pane *wp, int scroll_only)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data->screen.sel.flag || !data->rectflag) {
|
if (data->screen.sel != NULL || !data->rectflag) {
|
||||||
py = screen_hsize(data->backing) + data->cy - data->oy;
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
||||||
px = window_copy_find_length(wp, py);
|
px = window_copy_find_length(wp, py);
|
||||||
if ((data->cx >= data->lastsx && data->cx != px) ||
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
||||||
@@ -2063,9 +2087,9 @@ window_copy_cursor_up(struct window_pane *wp, int scroll_only)
|
|||||||
window_copy_cursor_end_of_line(wp);
|
window_copy_cursor_end_of_line(wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->sel.lineflag == LINE_SEL_LEFT_RIGHT)
|
if (data->lineflag == LINE_SEL_LEFT_RIGHT)
|
||||||
window_copy_cursor_end_of_line(wp);
|
window_copy_cursor_end_of_line(wp);
|
||||||
else if (s->sel.lineflag == LINE_SEL_RIGHT_LEFT)
|
else if (data->lineflag == LINE_SEL_RIGHT_LEFT)
|
||||||
window_copy_cursor_start_of_line(wp);
|
window_copy_cursor_start_of_line(wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2083,7 +2107,7 @@ window_copy_cursor_down(struct window_pane *wp, int scroll_only)
|
|||||||
data->lastsx = ox;
|
data->lastsx = ox;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->sel.lineflag == LINE_SEL_RIGHT_LEFT && oy == data->endsely)
|
if (data->lineflag == LINE_SEL_RIGHT_LEFT && oy == data->endsely)
|
||||||
window_copy_other_end(wp);
|
window_copy_other_end(wp);
|
||||||
|
|
||||||
data->cx = data->lastcx;
|
data->cx = data->lastcx;
|
||||||
@@ -2097,7 +2121,7 @@ window_copy_cursor_down(struct window_pane *wp, int scroll_only)
|
|||||||
window_copy_redraw_lines(wp, data->cy - 1, 2);
|
window_copy_redraw_lines(wp, data->cy - 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data->screen.sel.flag || !data->rectflag) {
|
if (data->screen.sel == NULL || !data->rectflag) {
|
||||||
py = screen_hsize(data->backing) + data->cy - data->oy;
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
||||||
px = window_copy_find_length(wp, py);
|
px = window_copy_find_length(wp, py);
|
||||||
if ((data->cx >= data->lastsx && data->cx != px) ||
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
||||||
@@ -2105,9 +2129,9 @@ window_copy_cursor_down(struct window_pane *wp, int scroll_only)
|
|||||||
window_copy_cursor_end_of_line(wp);
|
window_copy_cursor_end_of_line(wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->sel.lineflag == LINE_SEL_LEFT_RIGHT)
|
if (data->lineflag == LINE_SEL_LEFT_RIGHT)
|
||||||
window_copy_cursor_end_of_line(wp);
|
window_copy_cursor_end_of_line(wp);
|
||||||
else if (s->sel.lineflag == LINE_SEL_RIGHT_LEFT)
|
else if (data->lineflag == LINE_SEL_RIGHT_LEFT)
|
||||||
window_copy_cursor_start_of_line(wp);
|
window_copy_cursor_start_of_line(wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2166,14 +2190,14 @@ window_copy_cursor_jump_back(struct window_pane *wp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_copy_cursor_jump_to(struct window_pane *wp, int jump_again)
|
window_copy_cursor_jump_to(struct window_pane *wp)
|
||||||
{
|
{
|
||||||
struct window_copy_mode_data *data = wp->modedata;
|
struct window_copy_mode_data *data = wp->modedata;
|
||||||
struct screen *back_s = data->backing;
|
struct screen *back_s = data->backing;
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
u_int px, py, xx;
|
u_int px, py, xx;
|
||||||
|
|
||||||
px = data->cx + 1 + jump_again;
|
px = data->cx + 2;
|
||||||
py = screen_hsize(back_s) + data->cy - data->oy;
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
||||||
xx = window_copy_find_length(wp, py);
|
xx = window_copy_find_length(wp, py);
|
||||||
|
|
||||||
@@ -2191,7 +2215,7 @@ window_copy_cursor_jump_to(struct window_pane *wp, int jump_again)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_copy_cursor_jump_to_back(struct window_pane *wp, int jump_again)
|
window_copy_cursor_jump_to_back(struct window_pane *wp)
|
||||||
{
|
{
|
||||||
struct window_copy_mode_data *data = wp->modedata;
|
struct window_copy_mode_data *data = wp->modedata;
|
||||||
struct screen *back_s = data->backing;
|
struct screen *back_s = data->backing;
|
||||||
@@ -2204,7 +2228,7 @@ window_copy_cursor_jump_to_back(struct window_pane *wp, int jump_again)
|
|||||||
if (px > 0)
|
if (px > 0)
|
||||||
px--;
|
px--;
|
||||||
|
|
||||||
if (jump_again && px > 0)
|
if (px > 0)
|
||||||
px--;
|
px--;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -2378,7 +2402,7 @@ window_copy_scroll_up(struct window_pane *wp, u_int ny)
|
|||||||
window_copy_write_line(wp, &ctx, 1);
|
window_copy_write_line(wp, &ctx, 1);
|
||||||
if (screen_size_y(s) > 3)
|
if (screen_size_y(s) > 3)
|
||||||
window_copy_write_line(wp, &ctx, screen_size_y(s) - 2);
|
window_copy_write_line(wp, &ctx, screen_size_y(s) - 2);
|
||||||
if (s->sel.flag && screen_size_y(s) > ny)
|
if (s->sel != NULL && screen_size_y(s) > ny)
|
||||||
window_copy_write_line(wp, &ctx, screen_size_y(s) - ny - 1);
|
window_copy_write_line(wp, &ctx, screen_size_y(s) - ny - 1);
|
||||||
screen_write_cursormove(&ctx, data->cx, data->cy);
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
||||||
screen_write_stop(&ctx);
|
screen_write_stop(&ctx);
|
||||||
@@ -2406,7 +2430,7 @@ window_copy_scroll_down(struct window_pane *wp, u_int ny)
|
|||||||
screen_write_cursormove(&ctx, 0, 0);
|
screen_write_cursormove(&ctx, 0, 0);
|
||||||
screen_write_insertline(&ctx, ny, 8);
|
screen_write_insertline(&ctx, ny, 8);
|
||||||
window_copy_write_lines(wp, &ctx, 0, ny);
|
window_copy_write_lines(wp, &ctx, 0, ny);
|
||||||
if (s->sel.flag && screen_size_y(s) > ny)
|
if (s->sel != NULL && screen_size_y(s) > ny)
|
||||||
window_copy_write_line(wp, &ctx, ny);
|
window_copy_write_line(wp, &ctx, ny);
|
||||||
else if (ny == 1) /* nuke position */
|
else if (ny == 1) /* nuke position */
|
||||||
window_copy_write_line(wp, &ctx, 1);
|
window_copy_write_line(wp, &ctx, 1);
|
||||||
@@ -2418,13 +2442,13 @@ void
|
|||||||
window_copy_add_formats(struct window_pane *wp, struct format_tree *ft)
|
window_copy_add_formats(struct window_pane *wp, struct format_tree *ft)
|
||||||
{
|
{
|
||||||
struct window_copy_mode_data *data = wp->modedata;
|
struct window_copy_mode_data *data = wp->modedata;
|
||||||
struct screen *s = &data->screen;
|
|
||||||
|
|
||||||
if (wp->mode != &window_copy_mode)
|
if (wp->mode != &window_copy_mode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
format_add(ft, "selection_present", "%d", s->sel.flag);
|
format_add(ft, "selection_present", "%d", data->screen.sel != NULL);
|
||||||
format_add(ft, "scroll_position", "%d", data->oy);
|
format_add(ft, "scroll_position", "%d", data->oy);
|
||||||
|
format_add(ft, "rectangle_toggle", "%d", data->rectflag);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
364
window-tree.c
364
window-tree.c
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -43,8 +44,10 @@ static void window_tree_key(struct window_pane *,
|
|||||||
"#{?#{==:#{window_panes},1}, \"#{pane_title}\",}" \
|
"#{?#{==:#{window_panes},1}, \"#{pane_title}\",}" \
|
||||||
"," \
|
"," \
|
||||||
"#{session_windows} windows" \
|
"#{session_windows} windows" \
|
||||||
"#{?session_grouped, (group ,}" \
|
"#{?session_grouped, " \
|
||||||
"#{session_group}#{?session_grouped,),}" \
|
"(group #{session_group}: " \
|
||||||
|
"#{session_group_list})," \
|
||||||
|
"}" \
|
||||||
"#{?session_attached, (attached),}" \
|
"#{?session_attached, (attached),}" \
|
||||||
"}" \
|
"}" \
|
||||||
"}"
|
"}"
|
||||||
@@ -91,17 +94,23 @@ struct window_tree_modedata {
|
|||||||
struct mode_tree_data *data;
|
struct mode_tree_data *data;
|
||||||
char *format;
|
char *format;
|
||||||
char *command;
|
char *command;
|
||||||
|
int squash_groups;
|
||||||
|
|
||||||
struct window_tree_itemdata **item_list;
|
struct window_tree_itemdata **item_list;
|
||||||
u_int item_size;
|
u_int item_size;
|
||||||
|
|
||||||
struct client *client;
|
|
||||||
const char *entered;
|
const char *entered;
|
||||||
|
|
||||||
struct cmd_find_state fs;
|
struct cmd_find_state fs;
|
||||||
enum window_tree_type type;
|
enum window_tree_type type;
|
||||||
|
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
|
int left;
|
||||||
|
int right;
|
||||||
|
u_int start;
|
||||||
|
u_int end;
|
||||||
|
u_int each;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -288,7 +297,8 @@ window_tree_build_window(struct session *s, struct winlink *wl, void* modedata,
|
|||||||
free(text);
|
free(text);
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
wp = TAILQ_FIRST(&wl->window->panes);
|
if ((wp = TAILQ_FIRST(&wl->window->panes)) == NULL)
|
||||||
|
goto empty;
|
||||||
if (TAILQ_NEXT(wp, entry) == NULL) {
|
if (TAILQ_NEXT(wp, entry) == NULL) {
|
||||||
if (!window_tree_filter_pane(s, wl, wp, filter))
|
if (!window_tree_filter_pane(s, wl, wp, filter))
|
||||||
goto empty;
|
goto empty;
|
||||||
@@ -395,8 +405,11 @@ window_tree_build(void *modedata, u_int sort_type, uint64_t *tag,
|
|||||||
{
|
{
|
||||||
struct window_tree_modedata *data = modedata;
|
struct window_tree_modedata *data = modedata;
|
||||||
struct session *s, **l;
|
struct session *s, **l;
|
||||||
|
struct session_group *sg, *current;
|
||||||
u_int n, i;
|
u_int n, i;
|
||||||
|
|
||||||
|
current = session_group_contains(data->fs.s);
|
||||||
|
|
||||||
for (i = 0; i < data->item_size; i++)
|
for (i = 0; i < data->item_size; i++)
|
||||||
window_tree_free_item(data->item_list[i]);
|
window_tree_free_item(data->item_list[i]);
|
||||||
free(data->item_list);
|
free(data->item_list);
|
||||||
@@ -406,6 +419,12 @@ window_tree_build(void *modedata, u_int sort_type, uint64_t *tag,
|
|||||||
l = NULL;
|
l = NULL;
|
||||||
n = 0;
|
n = 0;
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
|
if (data->squash_groups &&
|
||||||
|
(sg = session_group_contains(s)) != NULL) {
|
||||||
|
if ((sg == current && s != data->fs.s) ||
|
||||||
|
(sg != current && s != TAILQ_FIRST(&sg->sessions)))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
l = xreallocarray(l, n + 1, sizeof *l);
|
l = xreallocarray(l, n + 1, sizeof *l);
|
||||||
l[n++] = s;
|
l[n++] = s;
|
||||||
}
|
}
|
||||||
@@ -434,11 +453,36 @@ window_tree_build(void *modedata, u_int sort_type, uint64_t *tag,
|
|||||||
*tag = (uint64_t)data->fs.wl;
|
*tag = (uint64_t)data->fs.wl;
|
||||||
break;
|
break;
|
||||||
case WINDOW_TREE_PANE:
|
case WINDOW_TREE_PANE:
|
||||||
*tag = (uint64_t)data->fs.wp;
|
if (window_count_panes(data->fs.wl->window) == 1)
|
||||||
|
*tag = (uint64_t)data->fs.wl;
|
||||||
|
else
|
||||||
|
*tag = (uint64_t)data->fs.wp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
window_tree_draw_label(struct screen_write_ctx *ctx, u_int px, u_int py,
|
||||||
|
u_int sx, u_int sy, const struct grid_cell *gc, const char *label)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
u_int ox, oy;
|
||||||
|
|
||||||
|
len = strlen(label);
|
||||||
|
if (sx == 0 || sy == 1 || len > sx)
|
||||||
|
return;
|
||||||
|
ox = (sx - len + 1) / 2;
|
||||||
|
oy = (sy + 1) / 2;
|
||||||
|
|
||||||
|
if (ox > 1 && ox + len < sx - 1 && sy >= 3) {
|
||||||
|
screen_write_cursormove(ctx, px + ox - 1, py + oy - 1);
|
||||||
|
screen_write_box(ctx, len + 2, 3);
|
||||||
|
}
|
||||||
|
screen_write_cursormove(ctx, px + ox, py + oy);
|
||||||
|
screen_write_puts(ctx, gc, "%s", label);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_tree_draw_session(struct window_tree_modedata *data, struct session *s,
|
window_tree_draw_session(struct window_tree_modedata *data, struct session *s,
|
||||||
struct screen_write_ctx *ctx, u_int sx, u_int sy)
|
struct screen_write_ctx *ctx, u_int sx, u_int sy)
|
||||||
@@ -446,12 +490,12 @@ window_tree_draw_session(struct window_tree_modedata *data, struct session *s,
|
|||||||
struct options *oo = s->options;
|
struct options *oo = s->options;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
|
u_int cx = ctx->s->cx, cy = ctx->s->cy;
|
||||||
u_int loop, total, visible, each, width, offset;
|
u_int loop, total, visible, each, width, offset;
|
||||||
u_int current, start, end, remaining, i;
|
u_int current, start, end, remaining, i;
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
int colour, active_colour, left, right;
|
int colour, active_colour, left, right;
|
||||||
char *label;
|
char *label;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
total = winlink_count(&s->windows);
|
total = winlink_count(&s->windows);
|
||||||
|
|
||||||
@@ -509,17 +553,25 @@ window_tree_draw_session(struct window_tree_modedata *data, struct session *s,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (left) {
|
if (left) {
|
||||||
screen_write_cursormove(ctx, 2, 0);
|
data->left = cx + 2;
|
||||||
|
screen_write_cursormove(ctx, cx + 2, cy);
|
||||||
screen_write_vline(ctx, sy, 0, 0);
|
screen_write_vline(ctx, sy, 0, 0);
|
||||||
screen_write_cursormove(ctx, 0, sy / 2);
|
screen_write_cursormove(ctx, cx, cy + sy / 2);
|
||||||
screen_write_puts(ctx, &grid_default_cell, "<");
|
screen_write_puts(ctx, &grid_default_cell, "<");
|
||||||
}
|
} else
|
||||||
|
data->left = -1;
|
||||||
if (right) {
|
if (right) {
|
||||||
screen_write_cursormove(ctx, sx - 3, 0);
|
data->right = cx + sx - 3;
|
||||||
|
screen_write_cursormove(ctx, cx + sx - 3, cy);
|
||||||
screen_write_vline(ctx, sy, 0, 0);
|
screen_write_vline(ctx, sy, 0, 0);
|
||||||
screen_write_cursormove(ctx, sx - 1, sy / 2);
|
screen_write_cursormove(ctx, cx + sx - 1, cy + sy / 2);
|
||||||
screen_write_puts(ctx, &grid_default_cell, ">");
|
screen_write_puts(ctx, &grid_default_cell, ">");
|
||||||
}
|
} else
|
||||||
|
data->right = -1;
|
||||||
|
|
||||||
|
data->start = start;
|
||||||
|
data->end = end;
|
||||||
|
data->each = each;
|
||||||
|
|
||||||
i = loop = 0;
|
i = loop = 0;
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
@@ -545,20 +597,18 @@ window_tree_draw_session(struct window_tree_modedata *data, struct session *s,
|
|||||||
else
|
else
|
||||||
width = each - 1;
|
width = each - 1;
|
||||||
|
|
||||||
screen_write_cursormove(ctx, offset, 0);
|
screen_write_cursormove(ctx, cx + offset, cy);
|
||||||
screen_write_preview(ctx, &w->active->base, width, sy);
|
screen_write_preview(ctx, &w->active->base, width, sy);
|
||||||
|
|
||||||
xasprintf(&label, " %u:%s ", wl->idx, w->name);
|
xasprintf(&label, " %u:%s ", wl->idx, w->name);
|
||||||
if (strlen(label) > width)
|
if (strlen(label) > width)
|
||||||
xasprintf(&label, " %u ", wl->idx);
|
xasprintf(&label, " %u ", wl->idx);
|
||||||
len = strlen(label) / 2;
|
window_tree_draw_label(ctx, cx + offset, cy, width, sy, &gc,
|
||||||
screen_write_cursormove(ctx, offset + (each / 2) - len, sy / 2);
|
label);
|
||||||
if (len < width)
|
|
||||||
screen_write_puts(ctx, &gc, "%s", label);
|
|
||||||
free(label);
|
free(label);
|
||||||
|
|
||||||
if (loop != end - 1) {
|
if (loop != end - 1) {
|
||||||
screen_write_cursormove(ctx, offset + width, 0);
|
screen_write_cursormove(ctx, cx + offset + width, cy);
|
||||||
screen_write_vline(ctx, sy, 0, 0);
|
screen_write_vline(ctx, sy, 0, 0);
|
||||||
}
|
}
|
||||||
loop++;
|
loop++;
|
||||||
@@ -573,12 +623,12 @@ window_tree_draw_window(struct window_tree_modedata *data, struct session *s,
|
|||||||
{
|
{
|
||||||
struct options *oo = s->options;
|
struct options *oo = s->options;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
|
u_int cx = ctx->s->cx, cy = ctx->s->cy;
|
||||||
u_int loop, total, visible, each, width, offset;
|
u_int loop, total, visible, each, width, offset;
|
||||||
u_int current, start, end, remaining, i;
|
u_int current, start, end, remaining, i;
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
int colour, active_colour, left, right;
|
int colour, active_colour, left, right, pane_idx;
|
||||||
char *label;
|
char *label;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
total = window_count_panes(w);
|
total = window_count_panes(w);
|
||||||
|
|
||||||
@@ -636,17 +686,25 @@ window_tree_draw_window(struct window_tree_modedata *data, struct session *s,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (left) {
|
if (left) {
|
||||||
screen_write_cursormove(ctx, 2, 0);
|
data->left = cx + 2;
|
||||||
|
screen_write_cursormove(ctx, cx + 2, cy);
|
||||||
screen_write_vline(ctx, sy, 0, 0);
|
screen_write_vline(ctx, sy, 0, 0);
|
||||||
screen_write_cursormove(ctx, 0, sy / 2);
|
screen_write_cursormove(ctx, cx, cy + sy / 2);
|
||||||
screen_write_puts(ctx, &grid_default_cell, "<");
|
screen_write_puts(ctx, &grid_default_cell, "<");
|
||||||
}
|
} else
|
||||||
|
data->left = -1;
|
||||||
if (right) {
|
if (right) {
|
||||||
screen_write_cursormove(ctx, sx - 3, 0);
|
data->right = cx + sx - 3;
|
||||||
|
screen_write_cursormove(ctx, cx + sx - 3, cy);
|
||||||
screen_write_vline(ctx, sy, 0, 0);
|
screen_write_vline(ctx, sy, 0, 0);
|
||||||
screen_write_cursormove(ctx, sx - 1, sy / 2);
|
screen_write_cursormove(ctx, cx + sx - 1, cy + sy / 2);
|
||||||
screen_write_puts(ctx, &grid_default_cell, ">");
|
screen_write_puts(ctx, &grid_default_cell, ">");
|
||||||
}
|
} else
|
||||||
|
data->right = -1;
|
||||||
|
|
||||||
|
data->start = start;
|
||||||
|
data->end = end;
|
||||||
|
data->each = each;
|
||||||
|
|
||||||
i = loop = 0;
|
i = loop = 0;
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
@@ -671,18 +729,18 @@ window_tree_draw_window(struct window_tree_modedata *data, struct session *s,
|
|||||||
else
|
else
|
||||||
width = each - 1;
|
width = each - 1;
|
||||||
|
|
||||||
screen_write_cursormove(ctx, offset, 0);
|
screen_write_cursormove(ctx, cx + offset, cy);
|
||||||
screen_write_preview(ctx, &wp->base, width, sy);
|
screen_write_preview(ctx, &wp->base, width, sy);
|
||||||
|
|
||||||
xasprintf(&label, " %u ", loop);
|
if (window_pane_index(wp, &pane_idx) != 0)
|
||||||
len = strlen(label) / 2;
|
pane_idx = loop;
|
||||||
screen_write_cursormove(ctx, offset + (each / 2) - len, sy / 2);
|
xasprintf(&label, " %u ", pane_idx);
|
||||||
if (len < width)
|
window_tree_draw_label(ctx, cx + offset, cy, each, sy, &gc,
|
||||||
screen_write_puts(ctx, &gc, "%s", label);
|
label);
|
||||||
free(label);
|
free(label);
|
||||||
|
|
||||||
if (loop != end - 1) {
|
if (loop != end - 1) {
|
||||||
screen_write_cursormove(ctx, offset + width, 0);
|
screen_write_cursormove(ctx, cx + offset + width, cy);
|
||||||
screen_write_vline(ctx, sy, 0, 0);
|
screen_write_vline(ctx, sy, 0, 0);
|
||||||
}
|
}
|
||||||
loop++;
|
loop++;
|
||||||
@@ -691,39 +749,32 @@ window_tree_draw_window(struct window_tree_modedata *data, struct session *s,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct screen *
|
static void
|
||||||
window_tree_draw(void *modedata, void *itemdata, u_int sx, u_int sy)
|
window_tree_draw(void *modedata, void *itemdata, struct screen_write_ctx *ctx,
|
||||||
|
u_int sx, u_int sy)
|
||||||
{
|
{
|
||||||
struct window_tree_itemdata *item = itemdata;
|
struct window_tree_itemdata *item = itemdata;
|
||||||
struct session *sp;
|
struct session *sp;
|
||||||
struct winlink *wlp;
|
struct winlink *wlp;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
static struct screen s;
|
|
||||||
struct screen_write_ctx ctx;
|
|
||||||
|
|
||||||
window_tree_pull_item(item, &sp, &wlp, &wp);
|
window_tree_pull_item(item, &sp, &wlp, &wp);
|
||||||
if (wp == NULL)
|
if (wp == NULL)
|
||||||
return (NULL);
|
return;
|
||||||
|
|
||||||
screen_init(&s, sx, sy, 0);
|
|
||||||
screen_write_start(&ctx, NULL, &s);
|
|
||||||
|
|
||||||
switch (item->type) {
|
switch (item->type) {
|
||||||
case WINDOW_TREE_NONE:
|
case WINDOW_TREE_NONE:
|
||||||
return (0);
|
break;
|
||||||
case WINDOW_TREE_SESSION:
|
case WINDOW_TREE_SESSION:
|
||||||
window_tree_draw_session(modedata, sp, &ctx, sx, sy);
|
window_tree_draw_session(modedata, sp, ctx, sx, sy);
|
||||||
break;
|
break;
|
||||||
case WINDOW_TREE_WINDOW:
|
case WINDOW_TREE_WINDOW:
|
||||||
window_tree_draw_window(modedata, sp, wlp->window, &ctx, sx, sy);
|
window_tree_draw_window(modedata, sp, wlp->window, ctx, sx, sy);
|
||||||
break;
|
break;
|
||||||
case WINDOW_TREE_PANE:
|
case WINDOW_TREE_PANE:
|
||||||
screen_write_preview(&ctx, &wp->base, sx, sy);
|
screen_write_preview(ctx, &wp->base, sx, sy);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_write_stop(&ctx);
|
|
||||||
return (&s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -787,10 +838,12 @@ window_tree_init(struct window_pane *wp, struct cmd_find_state *fs,
|
|||||||
data->command = xstrdup(WINDOW_TREE_DEFAULT_COMMAND);
|
data->command = xstrdup(WINDOW_TREE_DEFAULT_COMMAND);
|
||||||
else
|
else
|
||||||
data->command = xstrdup(args->argv[0]);
|
data->command = xstrdup(args->argv[0]);
|
||||||
|
data->squash_groups = !args_has(args, 'G');
|
||||||
|
|
||||||
data->data = mode_tree_start(wp, args, window_tree_build,
|
data->data = mode_tree_start(wp, args, window_tree_build,
|
||||||
window_tree_draw, window_tree_search, data, window_tree_sort_list,
|
window_tree_draw, window_tree_search, data, window_tree_sort_list,
|
||||||
nitems(window_tree_sort_list), &s);
|
nitems(window_tree_sort_list), &s);
|
||||||
|
mode_tree_zoom(data->data, args);
|
||||||
|
|
||||||
mode_tree_build(data->data);
|
mode_tree_build(data->data);
|
||||||
mode_tree_draw(data->data);
|
mode_tree_draw(data->data);
|
||||||
@@ -808,8 +861,6 @@ window_tree_destroy(struct window_tree_modedata *data)
|
|||||||
if (--data->references != 0)
|
if (--data->references != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mode_tree_free(data->data);
|
|
||||||
|
|
||||||
for (i = 0; i < data->item_size; i++)
|
for (i = 0; i < data->item_size; i++)
|
||||||
window_tree_free_item(data->item_list[i]);
|
window_tree_free_item(data->item_list[i]);
|
||||||
free(data->item_list);
|
free(data->item_list);
|
||||||
@@ -829,6 +880,7 @@ window_tree_free(struct window_pane *wp)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
data->dead = 1;
|
data->dead = 1;
|
||||||
|
mode_tree_free(data->data);
|
||||||
window_tree_destroy(data);
|
window_tree_destroy(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -879,7 +931,8 @@ window_tree_get_target(struct window_tree_itemdata *item,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_tree_command_each(void* modedata, void* itemdata, __unused key_code key)
|
window_tree_command_each(void* modedata, void* itemdata, struct client *c,
|
||||||
|
__unused key_code key)
|
||||||
{
|
{
|
||||||
struct window_tree_modedata *data = modedata;
|
struct window_tree_modedata *data = modedata;
|
||||||
struct window_tree_itemdata *item = itemdata;
|
struct window_tree_itemdata *item = itemdata;
|
||||||
@@ -888,7 +941,7 @@ window_tree_command_each(void* modedata, void* itemdata, __unused key_code key)
|
|||||||
|
|
||||||
name = window_tree_get_target(item, &fs);
|
name = window_tree_get_target(item, &fs);
|
||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
mode_tree_run_command(data->client, &fs, data->entered, name);
|
mode_tree_run_command(c, &fs, data->entered, name);
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -912,16 +965,12 @@ window_tree_command_callback(struct client *c, void *modedata, const char *s,
|
|||||||
{
|
{
|
||||||
struct window_tree_modedata *data = modedata;
|
struct window_tree_modedata *data = modedata;
|
||||||
|
|
||||||
if (data->dead)
|
if (s == NULL || *s == '\0' || data->dead)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
data->client = c;
|
|
||||||
data->entered = s;
|
data->entered = s;
|
||||||
|
mode_tree_each_tagged(data->data, window_tree_command_each, c,
|
||||||
mode_tree_each_tagged(data->data, window_tree_command_each, KEYC_NONE,
|
KEYC_NONE, 1);
|
||||||
1);
|
|
||||||
|
|
||||||
data->client = NULL;
|
|
||||||
data->entered = NULL;
|
data->entered = NULL;
|
||||||
|
|
||||||
data->references++;
|
data->references++;
|
||||||
@@ -938,21 +987,160 @@ window_tree_command_free(void *modedata)
|
|||||||
window_tree_destroy(data);
|
window_tree_destroy(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
window_tree_kill_each(__unused void* modedata, void* itemdata,
|
||||||
|
__unused struct client *c, __unused key_code key)
|
||||||
|
{
|
||||||
|
struct window_tree_itemdata *item = itemdata;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window_pane *wp;
|
||||||
|
|
||||||
|
window_tree_pull_item(item, &s, &wl, &wp);
|
||||||
|
|
||||||
|
switch (item->type) {
|
||||||
|
case WINDOW_TREE_NONE:
|
||||||
|
break;
|
||||||
|
case WINDOW_TREE_SESSION:
|
||||||
|
if (s != NULL) {
|
||||||
|
server_destroy_session(s);
|
||||||
|
session_destroy(s, __func__);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WINDOW_TREE_WINDOW:
|
||||||
|
if (wl != NULL)
|
||||||
|
server_kill_window(wl->window);
|
||||||
|
break;
|
||||||
|
case WINDOW_TREE_PANE:
|
||||||
|
if (wp != NULL)
|
||||||
|
server_kill_pane(wp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
window_tree_kill_current_callback(struct client *c, void *modedata,
|
||||||
|
const char *s, __unused int done)
|
||||||
|
{
|
||||||
|
struct window_tree_modedata *data = modedata;
|
||||||
|
struct mode_tree_data *mtd = data->data;
|
||||||
|
|
||||||
|
if (s == NULL || *s == '\0' || data->dead)
|
||||||
|
return (0);
|
||||||
|
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
window_tree_kill_each(data, mode_tree_get_current(mtd), c, KEYC_NONE);
|
||||||
|
|
||||||
|
data->references++;
|
||||||
|
cmdq_append(c, cmdq_get_callback(window_tree_command_done, data));
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
window_tree_kill_tagged_callback(struct client *c, void *modedata,
|
||||||
|
const char *s, __unused int done)
|
||||||
|
{
|
||||||
|
struct window_tree_modedata *data = modedata;
|
||||||
|
struct mode_tree_data *mtd = data->data;
|
||||||
|
|
||||||
|
if (s == NULL || *s == '\0' || data->dead)
|
||||||
|
return (0);
|
||||||
|
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
mode_tree_each_tagged(mtd, window_tree_kill_each, c, KEYC_NONE, 1);
|
||||||
|
|
||||||
|
data->references++;
|
||||||
|
cmdq_append(c, cmdq_get_callback(window_tree_command_done, data));
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static key_code
|
||||||
|
window_tree_mouse(struct window_tree_modedata *data, key_code key, u_int x,
|
||||||
|
struct window_tree_itemdata *item)
|
||||||
|
{
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window_pane *wp;
|
||||||
|
u_int loop;
|
||||||
|
|
||||||
|
if (key != KEYC_MOUSEDOWN1_PANE)
|
||||||
|
return (KEYC_NONE);
|
||||||
|
|
||||||
|
if (data->left != -1 && x <= (u_int)data->left)
|
||||||
|
return ('<');
|
||||||
|
if (data->right != -1 && x >= (u_int)data->right)
|
||||||
|
return ('>');
|
||||||
|
|
||||||
|
if (data->left != -1)
|
||||||
|
x -= data->left;
|
||||||
|
else if (x != 0)
|
||||||
|
x--;
|
||||||
|
if (x == 0 || data->end == 0)
|
||||||
|
x = 0;
|
||||||
|
else {
|
||||||
|
x = x / data->each;
|
||||||
|
if (data->start + x >= data->end)
|
||||||
|
x = data->end - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
window_tree_pull_item(item, &s, &wl, &wp);
|
||||||
|
if (item->type == WINDOW_TREE_SESSION) {
|
||||||
|
if (s == NULL)
|
||||||
|
return (KEYC_NONE);
|
||||||
|
mode_tree_expand_current(data->data);
|
||||||
|
loop = 0;
|
||||||
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
|
if (loop == data->start + x)
|
||||||
|
break;
|
||||||
|
loop++;
|
||||||
|
}
|
||||||
|
if (wl != NULL)
|
||||||
|
mode_tree_set_current(data->data, (uint64_t)wl);
|
||||||
|
return ('\r');
|
||||||
|
}
|
||||||
|
if (item->type == WINDOW_TREE_WINDOW) {
|
||||||
|
if (wl == NULL)
|
||||||
|
return (KEYC_NONE);
|
||||||
|
mode_tree_expand_current(data->data);
|
||||||
|
loop = 0;
|
||||||
|
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||||
|
if (loop == data->start + x)
|
||||||
|
break;
|
||||||
|
loop++;
|
||||||
|
}
|
||||||
|
if (wp != NULL)
|
||||||
|
mode_tree_set_current(data->data, (uint64_t)wp);
|
||||||
|
return ('\r');
|
||||||
|
}
|
||||||
|
return (KEYC_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_tree_key(struct window_pane *wp, struct client *c,
|
window_tree_key(struct window_pane *wp, struct client *c,
|
||||||
__unused struct session *s, key_code key, struct mouse_event *m)
|
__unused struct session *s, key_code key, struct mouse_event *m)
|
||||||
{
|
{
|
||||||
struct window_tree_modedata *data = wp->modedata;
|
struct window_tree_modedata *data = wp->modedata;
|
||||||
struct window_tree_itemdata *item;
|
struct window_tree_itemdata *item, *new_item;
|
||||||
char *command, *name, *prompt;
|
char *name, *prompt = NULL;
|
||||||
struct cmd_find_state fs;
|
struct cmd_find_state fs;
|
||||||
int finished;
|
int finished;
|
||||||
u_int tagged;
|
u_int tagged, x, y, idx;
|
||||||
|
struct session *ns;
|
||||||
|
struct winlink *nwl;
|
||||||
|
struct window_pane *nwp;
|
||||||
|
|
||||||
item = mode_tree_get_current(data->data);
|
item = mode_tree_get_current(data->data);
|
||||||
finished = mode_tree_key(data->data, c, &key, m);
|
finished = mode_tree_key(data->data, c, &key, m, &x, &y);
|
||||||
if (item != mode_tree_get_current(data->data))
|
if (item != (new_item = mode_tree_get_current(data->data))) {
|
||||||
|
item = new_item;
|
||||||
data->offset = 0;
|
data->offset = 0;
|
||||||
|
}
|
||||||
|
if (KEYC_IS_MOUSE(key))
|
||||||
|
key = window_tree_mouse(data, key, x, item);
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case '<':
|
case '<':
|
||||||
data->offset--;
|
data->offset--;
|
||||||
@@ -960,6 +1148,46 @@ window_tree_key(struct window_pane *wp, struct client *c,
|
|||||||
case '>':
|
case '>':
|
||||||
data->offset++;
|
data->offset++;
|
||||||
break;
|
break;
|
||||||
|
case 'x':
|
||||||
|
window_tree_pull_item(item, &ns, &nwl, &nwp);
|
||||||
|
switch (item->type) {
|
||||||
|
case WINDOW_TREE_NONE:
|
||||||
|
break;
|
||||||
|
case WINDOW_TREE_SESSION:
|
||||||
|
if (ns == NULL)
|
||||||
|
break;
|
||||||
|
xasprintf(&prompt, "Kill session %s? ", ns->name);
|
||||||
|
break;
|
||||||
|
case WINDOW_TREE_WINDOW:
|
||||||
|
if (nwl == NULL)
|
||||||
|
break;
|
||||||
|
xasprintf(&prompt, "Kill window %u? ", nwl->idx);
|
||||||
|
break;
|
||||||
|
case WINDOW_TREE_PANE:
|
||||||
|
if (nwp == NULL || window_pane_index(nwp, &idx) != 0)
|
||||||
|
break;
|
||||||
|
xasprintf(&prompt, "Kill pane %u? ", idx);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (prompt == NULL)
|
||||||
|
break;
|
||||||
|
data->references++;
|
||||||
|
status_prompt_set(c, prompt, "",
|
||||||
|
window_tree_kill_current_callback, window_tree_command_free,
|
||||||
|
data, PROMPT_SINGLE|PROMPT_NOFORMAT);
|
||||||
|
free(prompt);
|
||||||
|
break;
|
||||||
|
case 'X':
|
||||||
|
tagged = mode_tree_count_tagged(data->data);
|
||||||
|
if (tagged == 0)
|
||||||
|
break;
|
||||||
|
xasprintf(&prompt, "Kill %u tagged? ", tagged);
|
||||||
|
data->references++;
|
||||||
|
status_prompt_set(c, prompt, "",
|
||||||
|
window_tree_kill_tagged_callback, window_tree_command_free,
|
||||||
|
data, PROMPT_SINGLE|PROMPT_NOFORMAT);
|
||||||
|
free(prompt);
|
||||||
|
break;
|
||||||
case ':':
|
case ':':
|
||||||
tagged = mode_tree_count_tagged(data->data);
|
tagged = mode_tree_count_tagged(data->data);
|
||||||
if (tagged != 0)
|
if (tagged != 0)
|
||||||
@@ -973,14 +1201,12 @@ window_tree_key(struct window_pane *wp, struct client *c,
|
|||||||
break;
|
break;
|
||||||
case '\r':
|
case '\r':
|
||||||
item = mode_tree_get_current(data->data);
|
item = mode_tree_get_current(data->data);
|
||||||
command = xstrdup(data->command);
|
|
||||||
name = window_tree_get_target(item, &fs);
|
name = window_tree_get_target(item, &fs);
|
||||||
window_pane_reset_mode(wp);
|
|
||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
mode_tree_run_command(c, NULL, command, name);
|
mode_tree_run_command(c, NULL, data->command, name);
|
||||||
|
finished = 1;
|
||||||
free(name);
|
free(name);
|
||||||
free(command);
|
break;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (finished)
|
if (finished)
|
||||||
window_pane_reset_mode(wp);
|
window_pane_reset_mode(wp);
|
||||||
|
|||||||
39
window.c
39
window.c
@@ -339,7 +339,7 @@ window_create_spawn(const char *name, int argc, char **argv, const char *path,
|
|||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
|
|
||||||
w = window_create(sx, sy);
|
w = window_create(sx, sy);
|
||||||
wp = window_add_pane(w, NULL, 0, hlimit);
|
wp = window_add_pane(w, NULL, 0, 0, hlimit);
|
||||||
layout_init(w, wp);
|
layout_init(w, wp);
|
||||||
|
|
||||||
if (window_pane_spawn(wp, argc, argv, path, shell, cwd,
|
if (window_pane_spawn(wp, argc, argv, path, shell, cwd,
|
||||||
@@ -608,7 +608,7 @@ window_unzoom(struct window *w)
|
|||||||
|
|
||||||
struct window_pane *
|
struct window_pane *
|
||||||
window_add_pane(struct window *w, struct window_pane *other, int before,
|
window_add_pane(struct window *w, struct window_pane *other, int before,
|
||||||
u_int hlimit)
|
int full_size, u_int hlimit)
|
||||||
{
|
{
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
|
|
||||||
@@ -621,10 +621,16 @@ window_add_pane(struct window *w, struct window_pane *other, int before,
|
|||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
} else if (before) {
|
} else if (before) {
|
||||||
log_debug("%s: @%u before %%%u", __func__, w->id, wp->id);
|
log_debug("%s: @%u before %%%u", __func__, w->id, wp->id);
|
||||||
TAILQ_INSERT_BEFORE(other, wp, entry);
|
if (full_size)
|
||||||
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
|
else
|
||||||
|
TAILQ_INSERT_BEFORE(other, wp, entry);
|
||||||
} else {
|
} else {
|
||||||
log_debug("%s: @%u after %%%u", __func__, w->id, wp->id);
|
log_debug("%s: @%u after %%%u", __func__, w->id, wp->id);
|
||||||
TAILQ_INSERT_AFTER(&w->panes, other, wp, entry);
|
if (full_size)
|
||||||
|
TAILQ_INSERT_TAIL(&w->panes, wp, entry);
|
||||||
|
else
|
||||||
|
TAILQ_INSERT_AFTER(&w->panes, other, wp, entry);
|
||||||
}
|
}
|
||||||
return (wp);
|
return (wp);
|
||||||
}
|
}
|
||||||
@@ -912,12 +918,14 @@ window_pane_spawn(struct window_pane *wp, int argc, char **argv,
|
|||||||
free((void *)wp->cwd);
|
free((void *)wp->cwd);
|
||||||
wp->cwd = xstrdup(cwd);
|
wp->cwd = xstrdup(cwd);
|
||||||
}
|
}
|
||||||
|
wp->flags &= ~(PANE_STATUSREADY|PANE_STATUSDRAWN);
|
||||||
|
|
||||||
cmd = cmd_stringify_argv(wp->argc, wp->argv);
|
cmd = cmd_stringify_argv(wp->argc, wp->argv);
|
||||||
log_debug("spawn: %s -- %s", wp->shell, cmd);
|
log_debug("%s: shell=%s", __func__, wp->shell);
|
||||||
for (i = 0; i < wp->argc; i++)
|
log_debug("%s: cmd=%s", __func__, cmd);
|
||||||
log_debug("spawn: argv[%d] = %s", i, wp->argv[i]);
|
log_debug("%s: cwd=%s", __func__, cwd);
|
||||||
environ_log(env, "spawn: ");
|
cmd_log_argv(wp->argc, wp->argv, __func__);
|
||||||
|
environ_log(env, "%s: environment ", __func__);
|
||||||
|
|
||||||
memset(&ws, 0, sizeof ws);
|
memset(&ws, 0, sizeof ws);
|
||||||
ws.ws_col = screen_size_x(&wp->base);
|
ws.ws_col = screen_size_x(&wp->base);
|
||||||
@@ -938,10 +946,13 @@ window_pane_spawn(struct window_pane *wp, int argc, char **argv,
|
|||||||
proc_clear_signals(server_proc, 1);
|
proc_clear_signals(server_proc, 1);
|
||||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||||
|
|
||||||
if (chdir(wp->cwd) != 0) {
|
cwd = NULL;
|
||||||
if ((home = find_home()) == NULL || chdir(home) != 0)
|
if (chdir(wp->cwd) == 0)
|
||||||
chdir("/");
|
cwd = wp->cwd;
|
||||||
}
|
else if ((home = find_home()) != NULL && chdir(home) == 0)
|
||||||
|
cwd = home;
|
||||||
|
else
|
||||||
|
chdir("/");
|
||||||
|
|
||||||
if (tcgetattr(STDIN_FILENO, &tio2) != 0)
|
if (tcgetattr(STDIN_FILENO, &tio2) != 0)
|
||||||
fatal("tcgetattr failed");
|
fatal("tcgetattr failed");
|
||||||
@@ -959,6 +970,8 @@ window_pane_spawn(struct window_pane *wp, int argc, char **argv,
|
|||||||
|
|
||||||
if (path != NULL)
|
if (path != NULL)
|
||||||
environ_set(env, "PATH", "%s", path);
|
environ_set(env, "PATH", "%s", path);
|
||||||
|
if (cwd != NULL)
|
||||||
|
environ_set(env, "PWD", "%s", cwd);
|
||||||
environ_set(env, "TMUX_PANE", "%%%u", wp->id);
|
environ_set(env, "TMUX_PANE", "%%%u", wp->id);
|
||||||
environ_push(env);
|
environ_push(env);
|
||||||
|
|
||||||
@@ -993,6 +1006,8 @@ window_pane_spawn(struct window_pane *wp, int argc, char **argv,
|
|||||||
execl(wp->shell, argv0, (char *)NULL);
|
execl(wp->shell, argv0, (char *)NULL);
|
||||||
fatal("execl failed");
|
fatal("execl failed");
|
||||||
}
|
}
|
||||||
|
log_debug("%s: master=%s", __func__, ttyname(wp->fd));
|
||||||
|
log_debug("%s: slave=%s", __func__, wp->tty);
|
||||||
|
|
||||||
#ifdef HAVE_UTEMPTER
|
#ifdef HAVE_UTEMPTER
|
||||||
xsnprintf(s, sizeof s, "tmux(%lu).%%%u", (long) getpid(), wp->id);
|
xsnprintf(s, sizeof s, "tmux(%lu).%%%u", (long) getpid(), wp->id);
|
||||||
|
|||||||
Reference in New Issue
Block a user