Change behavior of pane

This commit is contained in:
oupson 2023-03-03 11:52:44 +01:00
parent 2167084fa6
commit 33c93a90b6
Signed by: oupson
GPG Key ID: 3BD88615552EFCB7
3 changed files with 45 additions and 17 deletions

View File

@ -1,5 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="FootermPane" parent="GtkBox">
<child>
<object id="footerm_pane_stack" class="AdwViewStack">
<property name="vexpand">True</property>
<child>
<object id="new_pane" class="FootermNewPane"></object>
</child>
<child>
<object id="terminal_pane" class="FootermTerminalPane"></object>
</child>
</object>
</child>
</template>
</interface>

View File

@ -21,15 +21,23 @@
namespace Footerm {
[GtkTemplate (ui = "/fr/oupson/FooTerm/pane.ui")]
public class Pane : Gtk.Box {
[GtkChild]
private unowned Adw.ViewStack footerm_pane_stack;
[GtkChild]
private unowned Footerm.NewPane new_pane;
[GtkChild]
private unowned Footerm.TerminalPane terminal_pane;
construct {
var new_pane = new Footerm.NewPane();
ulong handler_id;
handler_id = new_pane.on_server_selected.connect((s) => {
new_pane.disconnect (handler_id);
this.remove(new_pane);
this.append(new Footerm.TerminalPane(s));
this.new_pane.on_server_selected.connect ((s) => {
this.footerm_pane_stack.set_visible_child (this.terminal_pane);
this.terminal_pane.connect (s);
});
this.append(new_pane);
}
async void close () {
}
}
}

View File

@ -27,11 +27,21 @@ namespace Footerm {
private SSH2.Session<bool>? session;
private SSH2.Channel? channel;
private SocketConnection socket;
private int slave_pty;
private IOChannel slave_channel;
private Footerm.Model.Server server;
private Footerm.Model.Server? server;
public TerminalPane(Footerm.Model.Server server) {
public TerminalPane() {
this.terminal.char_size_changed.connect(() => {
int rows = 0;
int columns = 0;
this.terminal.get_pty().get_size(out rows, out columns);
this.channel.request_pty_size(columns, rows);
});
}
public void connect(Footerm.Model.Server server) {
this.server = server;
this.terminal.set_enable_sixel(true);
this.connect_to_server.begin((obj, res) => {
@ -134,8 +144,8 @@ namespace Footerm {
throw GLib.IOError.from_errno(Posix.errno);
}
this.slave_pty = Posix.open(pts_name, Posix.O_RDWR);
if (this.slave_pty < 0) {
var slave_pty = Posix.open(pts_name, Posix.O_RDWR);
if (slave_pty < 0) {
throw GLib.IOError.from_errno(Posix.errno);
}
@ -149,7 +159,7 @@ namespace Footerm {
source.set_callback(this.on_ssh_event);
source.attach(null);
var slave_channel = new GLib.IOChannel.unix_new(slave_pty);
this.slave_channel = new GLib.IOChannel.unix_new(slave_pty);
slave_channel.set_encoding(null);
slave_channel.set_buffered(false);
slave_channel.add_watch(GLib.IOCondition.IN, this.on_slave_event);
@ -169,9 +179,8 @@ namespace Footerm {
size = this.channel.read(buffer);
if (size > 0) {
debug("Got %zd bytes from ssh", size);
if (Posix.write(this.slave_pty, buffer, size) < 0) {
throw GLib.IOError.from_errno(Posix.errno);
}
size_t written_size = 0;
this.slave_channel.write_chars((char[]) (buffer[0 : size]), out written_size);
} else if ((size == 0 && channel.eof() != 0) || (size < 0 && size != SSH2.Error.AGAIN)) {
warning("Channel is closed");
return false;