Public Access
The Notes App lists the files of /notes by their first line, newest first: n starts a note, Enter opens it, r renames its file, d deletes it after asking, s sorts by name. A new note's file is named after its first line. The editor wraps at spaces, 38 columns by 8 rows; Fn+arrows move through the wrapped text, Ctrl+A and Ctrl+E go to the ends of the line. There is no save key: the note is written five seconds after the last key, on Back, on leaving the App, when the screen turns off and before the device powers off. A save writes a temporary file and puts it in the note's place; a save cut short is put back, or offered, the next time. A note is up to 16 KB, held in one buffer reserved when it's opened: the file is read straight into it and typing never makes it grow. A failed allocation aborts on this device, and with IRC connected the largest free block is about 31 KB: a first version that copied the note once on loading restarted the device when a full note was opened with IRC connected. Editing files of any size is #47. The Storage App's text viewer gets `e`, which edits a text file up to 16 KB with the same editor unless the file is read-only. 439 host tests. Checked on the device: docs/milestones/F1.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "app.h"
|
|
#include "apps/note_editor.h"
|
|
#include "dialog_model.h"
|
|
#include "file_list.h"
|
|
#include "line_editor.h"
|
|
#include "list_model.h"
|
|
#include "services/file_ops.h"
|
|
#include "ui/theme.h"
|
|
|
|
namespace roro {
|
|
|
|
// Notes (docs/milestones/F1.md, Q141-Q150): plain text files in /notes, listed by their first line,
|
|
// newest first. n starts one, Enter opens it in the editor, which saves by itself; r renames the
|
|
// file, d deletes it after asking, s sorts by name or by date.
|
|
class NotesApp : public App {
|
|
public:
|
|
NotesApp(FileOps& ops, StorageService& storage, ClockService& clock, PowerService& power)
|
|
: ops_(ops), storage_(storage), editor_(storage, clock, power) {}
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
bool onKey(const KeyEvent& e) override;
|
|
bool textEntryActive() const override { return view_ == View::Edit || view_ == View::Name; }
|
|
void update(uint32_t nowMs) override;
|
|
void draw(Canvas& c) override;
|
|
|
|
private:
|
|
enum class View { List, Edit, Name, NoMemory };
|
|
enum class Wait { None, List, Work };
|
|
static constexpr int kRows = 8;
|
|
static constexpr size_t kStartFloor = 55 * 1024; // Q86, Q144
|
|
static constexpr const char* kFolder = "/notes";
|
|
|
|
void reload(const std::string& select = "");
|
|
void onFinished(const FileOps::Status& s);
|
|
bool onListKey(const KeyEvent& e);
|
|
bool onNameKey(const KeyEvent& e);
|
|
void leaveEditor();
|
|
std::string selectedPath() const; // "" in an empty list
|
|
std::string titleOf(int row);
|
|
void readTitles();
|
|
void say(const std::string& text);
|
|
|
|
FileOps& ops_;
|
|
StorageService& storage_;
|
|
NoteEditor editor_;
|
|
|
|
View view_ = View::List;
|
|
files::FileList list_;
|
|
std::vector<uint16_t> notes_; // the entries of list_ that are notes
|
|
files::FileSort sort_ = files::FileSort::Date;
|
|
ListModel rows_{kRows};
|
|
bool wantList_ = false, loaded_ = false, cardPresent_ = false, mended_ = false;
|
|
std::string selectAfter_;
|
|
int selectIndex_ = 0;
|
|
Wait wait_ = Wait::None;
|
|
std::vector<std::string> titles_; // of the rows on screen
|
|
int titlesFrom_ = -1;
|
|
std::unique_ptr<DialogModel> dialog_;
|
|
std::string target_, question_;
|
|
LineEditor name_{40};
|
|
std::string message_;
|
|
uint32_t messageMs_ = 0, lastDrawMs_ = 0;
|
|
};
|
|
|
|
} // namespace roro
|