Skip to content

Commit

Permalink
added text_input visibility option
Browse files Browse the repository at this point in the history
  • Loading branch information
casperstorm committed Jul 9, 2023
1 parent d39824f commit c4302bc
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Unreleased

Added:

- Configuration option `new_buffer.input_visibility` to control input field visibility: always shown or following the focused buffer.

Fixed:

- Changes done in the config file are now properly applied to the old buffers


# 2023.2 (2023-07-07)

Added:
Expand Down
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ new_buffer:
left: "["
right: "]"

# Input visibility behaviour
# - Always: Show input at all times [default]
# - Focused: Only show input when the buffer is focused
input_visibility: Always

# Channel buffer settings
channel:
# User list settings
Expand Down
7 changes: 7 additions & 0 deletions data/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ impl From<config::Buffer> for Settings {
}
}

#[derive(Debug, Clone, Copy, Default, Deserialize)]
pub enum InputVisibility {
Focused,
#[default]
Always,
}

#[derive(Debug, Clone, Deserialize)]
pub struct Timestamp {
pub format: String,
Expand Down
5 changes: 4 additions & 1 deletion data/src/config/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chrono::{DateTime, Local, Utc};
use serde::Deserialize;

use super::Channel;
use crate::buffer::{Color, Nickname, Timestamp};
use crate::buffer::{Color, InputVisibility, Nickname, Timestamp};

#[derive(Debug, Clone, Deserialize)]
pub struct Buffer {
Expand All @@ -11,6 +11,8 @@ pub struct Buffer {
#[serde(default)]
pub nickname: Nickname,
#[serde(default)]
pub input_visibility: InputVisibility,
#[serde(default)]
pub channel: Channel,
}

Expand All @@ -25,6 +27,7 @@ impl Default for Buffer {
color: Color::Unique,
brackets: Default::default(),
},
input_visibility: InputVisibility::default(),
channel: Channel::default(),
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/buffer/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,20 @@ pub fn view<'a>(
.width(Length::FillPortion(2))
.height(Length::Fill);

let spacing = is_focused.then_some(vertical_space(4));
let users = clients.get_channel_users(&state.server, &state.channel);
let nick_list = nick_list::view(users).map(Message::UserContext);
let text_input = (is_focused && status.connected()).then(|| {
input_view::view(&state.input_view, buffer, users, input_history).map(Message::InputView)

let show_text_input = match config.buffer.input_visibility {
data::buffer::InputVisibility::Focused => is_focused && status.connected(),
data::buffer::InputVisibility::Always => status.connected(),
};

let text_input = show_text_input.then(|| {
column![
vertical_space(4),
input_view::view(&state.input_view, buffer, users, input_history)
.map(Message::InputView)
]
});

let content = match (settings.users.visible, config.buffer.channel.users.position) {
Expand All @@ -115,7 +124,6 @@ pub fn view<'a>(
};

let scrollable = column![container(content).height(Length::Fill)]
.push_maybe(spacing)
.push_maybe(text_input)
.height(Length::Fill);

Expand Down
15 changes: 11 additions & 4 deletions src/buffer/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,20 @@ pub fn view<'a>(
.map(Message::ScrollView),
)
.height(Length::Fill);
let spacing = is_focused.then_some(vertical_space(4));
let text_input = (is_focused && status.connected()).then(|| {
input_view::view(&state.input_view, buffer, &[], input_history).map(Message::InputView)

let show_text_input = match config.buffer.input_visibility {
data::buffer::InputVisibility::Focused => is_focused && status.connected(),
data::buffer::InputVisibility::Always => status.connected(),
};

let text_input = show_text_input.then(|| {
column![
vertical_space(4),
input_view::view(&state.input_view, buffer, &[], input_history).map(Message::InputView)
]
});

let scrollable = column![messages]
.push_maybe(spacing)
.push_maybe(text_input)
.height(Length::Fill);

Expand Down
15 changes: 11 additions & 4 deletions src/buffer/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ pub fn view<'a>(
.map(Message::ScrollView),
)
.height(Length::Fill);
let spacing = is_focused.then_some(vertical_space(4));
let text_input = (is_focused && status.connected()).then(|| {
input_view::view(&state.input_view, buffer, &[], input_history).map(Message::InputView)

let show_text_input = match config.buffer.input_visibility {
data::buffer::InputVisibility::Focused => is_focused && status.connected(),
data::buffer::InputVisibility::Always => status.connected(),
};

let text_input = show_text_input.then(|| {
column![
vertical_space(4),
input_view::view(&state.input_view, buffer, &[], input_history).map(Message::InputView)
]
});

let scrollable = column![messages]
.push_maybe(spacing)
.push_maybe(text_input)
.height(Length::Fill);

Expand Down

0 comments on commit c4302bc

Please sign in to comment.