feat(app): add the Nostro app, a window for phones and desktops
Linux phones have no banking apps, and a command line is no answer on a phone. The app does everything the nostro command does and, like it, only talks to nostrod: it holds no key and no token. - Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens; Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics; nostro-app; and Nostro.DebugCommands for the --debug-api build. - Client: every method also in an asynchronous form for an sd-event loop, with DaemonMissing and OutcomeUnknown. - nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both Flatpaks cross-built for aarch64, and the licence texts they carry. - nostro-fake-system, a made-up bus and bank with a real nostrod on them, to look at the app against. The README's screenshots are taken on it. - The nostro command: an API key's environment is the key's own to say, so --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL. The published contract changes in three places, before any release (design rule 10): - Transactions' query takes `stored`: answered from what nostrod has stored, without asking the bank. The app searches with it; before, every search was a call to bunq. - AddBunq's `environment` no longer chooses over what the key says of itself: a key of the other environment is refused. - SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one as DEACTIVATED however well it pays, and leaves it as it is when asked, without an error. The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved from one to the other (design rule 13). Transaction's schema is unchanged. Verified: the 17 tests pass with every line, function and region of what they link run, and the five lint runs are clean. Every screen was looked at on the made-up system, at a phone's and a desktop's sizes in the light and the dark look, on Plasma under Wayland. What is said of bunq's cards comes from its sandbox, with throwaway users, and from one real virtual card. Known to have been used against production: connecting, and reading accounts, payments and cards. Not known to have been tried: a payment from the app against bunq, OAuth against bunq, and anything on a phone. Building the app takes --graphics=, a Crafter.Graphics checkout on its branch claude/nostro-app, until that branch is merged and pinned here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
1ea50c50bc
commit
5b4037955b
106 changed files with 17804 additions and 289 deletions
223
implementations/Nostro.Ui-Edit.cpp
Normal file
223
implementations/Nostro.Ui-Edit.cpp
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
module;
|
||||
|
||||
#include <string.h>
|
||||
|
||||
module Nostro.Ui:Edit_impl;
|
||||
import std;
|
||||
import :Edit;
|
||||
import :Text;
|
||||
|
||||
using namespace Nostro::Ui;
|
||||
|
||||
namespace {
|
||||
// Overwrites a string's whole buffer, the part past its length too, where what was deleted from it may still be,
|
||||
// and empties it. explicit_bzero is the call a compiler may not take out as a write nobody reads.
|
||||
void Wipe(std::string& text) {
|
||||
text.resize(text.capacity());
|
||||
explicit_bzero(text.data(), text.size());
|
||||
text.clear();
|
||||
}
|
||||
|
||||
// What of `utf8` a field of `kind` takes.
|
||||
std::string Taken(std::string_view utf8, FieldKind kind) {
|
||||
std::string taken;
|
||||
for(std::size_t i = 0; i < utf8.size();) {
|
||||
const std::size_t at = i;
|
||||
const std::uint32_t codepoint = DecodeUtf8(utf8, i);
|
||||
const std::string_view bytes = utf8.substr(at, i - at);
|
||||
const bool digit = codepoint >= '0' && codepoint <= '9';
|
||||
if(kind == FieldKind::Decimal || kind == FieldKind::Digits) {
|
||||
if(digit || (kind == FieldKind::Decimal && (codepoint == '.' || codepoint == ','))) {
|
||||
taken += bytes;
|
||||
}
|
||||
} else if(codepoint == '\n' || codepoint == '\t') {
|
||||
// A field is one line: a break in prose that was pasted is a space, and one around a key or an address
|
||||
// (the newline a terminal's selection ends with) is nothing.
|
||||
if(kind == FieldKind::Text) {
|
||||
taken += ' ';
|
||||
}
|
||||
} else if(codepoint == ' ') {
|
||||
// A key has no space in it; an IBAN typed in groups keeps its own.
|
||||
if(kind != FieldKind::Secret) {
|
||||
taken += ' ';
|
||||
}
|
||||
} else if(codepoint >= 0x20 && codepoint != 0x7F && !(codepoint == 0xFFFD && bytes != "\xEF\xBF\xBD")) {
|
||||
// No control characters, and no malformed sequence, which decodes as U+FFFD without being its bytes: the
|
||||
// bus carries valid UTF-8 alone.
|
||||
taken += bytes;
|
||||
}
|
||||
}
|
||||
return taken;
|
||||
}
|
||||
}
|
||||
|
||||
EditState::EditState(FieldKind kind) : kind(kind) {
|
||||
if(kind == FieldKind::Secret) {
|
||||
value.reserve(secretLimit);
|
||||
}
|
||||
}
|
||||
|
||||
EditState::~EditState() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
bool EditState::Empty() const noexcept {
|
||||
return value.empty() && preedit.empty();
|
||||
}
|
||||
|
||||
std::string EditState::Shown() const {
|
||||
std::string shown = value;
|
||||
shown.insert(cursor, preedit);
|
||||
return shown;
|
||||
}
|
||||
|
||||
std::size_t EditState::ShownCursor() const noexcept {
|
||||
return cursor + preedit.size();
|
||||
}
|
||||
|
||||
bool EditState::HasSelection() const noexcept {
|
||||
return cursor != anchor;
|
||||
}
|
||||
|
||||
std::size_t EditState::SelectionBegin() const noexcept {
|
||||
return std::min(cursor, anchor);
|
||||
}
|
||||
|
||||
std::size_t EditState::SelectionEnd() const noexcept {
|
||||
return std::max(cursor, anchor);
|
||||
}
|
||||
|
||||
std::string_view EditState::Selected() const noexcept {
|
||||
return std::string_view(value).substr(SelectionBegin(), SelectionEnd() - SelectionBegin());
|
||||
}
|
||||
|
||||
void EditState::Set(std::string_view text) {
|
||||
Clear();
|
||||
Insert(text);
|
||||
}
|
||||
|
||||
void EditState::Clear() {
|
||||
if(kind == FieldKind::Secret) {
|
||||
Wipe(value);
|
||||
Wipe(preedit);
|
||||
}
|
||||
value.clear();
|
||||
preedit.clear();
|
||||
cursor = 0;
|
||||
anchor = 0;
|
||||
}
|
||||
|
||||
void EditState::Commit(std::string_view utf8) {
|
||||
preedit.clear();
|
||||
Insert(utf8);
|
||||
}
|
||||
|
||||
void EditState::Paste(std::string_view utf8) {
|
||||
CommitPreedit();
|
||||
Insert(utf8);
|
||||
}
|
||||
|
||||
bool EditState::Apply(EditKey key, bool extend) {
|
||||
if(key == EditKey::Backspace || key == EditKey::Delete) {
|
||||
if(DeleteSelection()) {
|
||||
return true;
|
||||
}
|
||||
const std::size_t from = key == EditKey::Backspace ? PreviousCodepoint(value, cursor) : cursor;
|
||||
const std::size_t to = key == EditKey::Backspace ? cursor : NextCodepoint(value, cursor);
|
||||
if(from == to) {
|
||||
return false;
|
||||
}
|
||||
value.erase(from, to - from);
|
||||
cursor = from;
|
||||
anchor = from;
|
||||
return true;
|
||||
}
|
||||
// A move that does not stretch a selection ends it: Left and Right at the side they point to.
|
||||
const bool collapse = HasSelection() && !extend;
|
||||
std::size_t to = value.size();
|
||||
if(key == EditKey::Left) {
|
||||
to = collapse ? SelectionBegin() : PreviousCodepoint(value, cursor);
|
||||
} else if(key == EditKey::Right) {
|
||||
to = collapse ? SelectionEnd() : NextCodepoint(value, cursor);
|
||||
} else if(key == EditKey::Home) {
|
||||
to = 0;
|
||||
}
|
||||
cursor = to;
|
||||
if(!extend) {
|
||||
anchor = to;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditState::DeleteAround(std::size_t beforeBytes, std::size_t afterBytes) {
|
||||
std::size_t from = cursor;
|
||||
while(from > 0 && cursor - from < beforeBytes) {
|
||||
from = PreviousCodepoint(value, from);
|
||||
}
|
||||
std::size_t to = cursor;
|
||||
while(to < value.size() && to - cursor < afterBytes) {
|
||||
to = NextCodepoint(value, to);
|
||||
}
|
||||
value.erase(from, to - from);
|
||||
cursor = from;
|
||||
anchor = from;
|
||||
}
|
||||
|
||||
void EditState::CommitPreedit() {
|
||||
if(preedit.empty()) {
|
||||
return;
|
||||
}
|
||||
std::string composing = std::exchange(preedit, std::string());
|
||||
Insert(composing);
|
||||
if(kind == FieldKind::Secret) {
|
||||
Wipe(composing);
|
||||
}
|
||||
}
|
||||
|
||||
void EditState::MoveTo(std::size_t byte) {
|
||||
std::size_t at = std::min(byte, value.size());
|
||||
while(at > 0 && at < value.size() && (static_cast<std::uint8_t>(value[at]) & 0xC0) == 0x80) {
|
||||
at--;
|
||||
}
|
||||
cursor = at;
|
||||
anchor = at;
|
||||
}
|
||||
|
||||
void EditState::SelectAll() {
|
||||
anchor = 0;
|
||||
cursor = value.size();
|
||||
}
|
||||
|
||||
bool EditState::DeleteSelection() {
|
||||
if(!HasSelection()) {
|
||||
return false;
|
||||
}
|
||||
const std::size_t from = SelectionBegin();
|
||||
value.erase(from, SelectionEnd() - from);
|
||||
cursor = from;
|
||||
anchor = from;
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditState::Insert(std::string_view utf8) {
|
||||
DeleteSelection();
|
||||
std::string taken = Taken(utf8, kind);
|
||||
// No more than the field holds, cut between code points.
|
||||
const std::size_t room = (kind == FieldKind::Secret ? secretLimit : limit) - std::min(value.size(), kind == FieldKind::Secret ? secretLimit : limit);
|
||||
if(taken.size() > room) {
|
||||
std::size_t cut = room;
|
||||
while(cut > 0 && (static_cast<std::uint8_t>(taken[cut]) & 0xC0) == 0x80) {
|
||||
cut--;
|
||||
}
|
||||
taken.resize(cut);
|
||||
}
|
||||
value.insert(cursor, taken);
|
||||
cursor += taken.size();
|
||||
anchor = cursor;
|
||||
if(kind == FieldKind::Secret) {
|
||||
Wipe(taken);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue