IRC App: Alt scrolls, Up/Down recall sent lines; /j for /join

- Alt + ; / Alt + . scroll the Buffer back and forward
- Up / Down (Fn + ; / Fn + .) browse the last 30 sent lines, shell-style,
  returning to the draft past the newest (InputHistory, host-tested)
- /j is short for /join

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
2026-10-03 20:12:33 +02:00
co-authored by Claude Opus 5.5
parent 1f0c1b2e14
commit 5ac6afa557
6 changed files with 152 additions and 4 deletions
+2 -2
View File
@@ -326,7 +326,7 @@ void IrcSession::command(int b, const std::string& text, int64_t utc) {
const IrcBuffer& buf = buffers_[b];
bool inChannel = buf.type == IrcBuffer::Type::Channel;
if (verb == "join") {
if (verb == "join" || verb == "j") {
auto [channel, key] = firstWord(rest);
if (channel.empty()) return info(b, "Usage: /join #channel", utc);
if (!isChannel(channel)) channel = "#" + channel;
@@ -362,7 +362,7 @@ void IrcSession::command(int b, const std::string& text, int64_t utc) {
} else if (verb == "raw" || verb == "quote") {
if (!rest.empty()) send(rest);
} else {
info(b, "Unknown command /" + verb + " (try /join /part /msg /me /nick /topic /names /quit /raw)", utc);
info(b, "Unknown command /" + verb + " (try /join or /j, /part /msg /me /nick /topic /names /quit /raw)", utc);
}
}
+50
View File
@@ -0,0 +1,50 @@
#pragma once
#include <deque>
#include <string>
namespace roro {
// Lines already entered, browsed shell-style: up() goes back in time, down() forward, and past the
// newest line the draft being typed comes back.
class InputHistory {
public:
explicit InputHistory(size_t capacity) : capacity_(capacity) {}
void add(const std::string& line) {
browsing_ = -1;
if (line.empty() || (!lines_.empty() && lines_.back() == line)) return;
lines_.push_back(line);
if (lines_.size() > capacity_) lines_.pop_front();
}
// `current` is what the editor holds now (kept as the draft when browsing starts).
bool up(const std::string& current, std::string& out) {
if (lines_.empty() || browsing_ == 0) return false;
if (browsing_ < 0) {
draft_ = current;
browsing_ = static_cast<int>(lines_.size());
}
out = lines_[--browsing_];
return true;
}
bool down(std::string& out) {
if (browsing_ < 0) return false;
if (++browsing_ >= static_cast<int>(lines_.size())) {
browsing_ = -1;
out = draft_;
} else {
out = lines_[browsing_];
}
return true;
}
private:
size_t capacity_;
std::deque<std::string> lines_;
int browsing_ = -1; // index being shown, -1 when editing the draft
std::string draft_;
};
} // namespace roro