From 06a128a3cda793e30e56efe5442cd33333e80352 Mon Sep 17 00:00:00 2001 From: Sebastian Hiebl Date: Sun, 12 Nov 2023 22:40:16 +0100 Subject: [PATCH] show chunk position in modeline --- src/ChunkedJournal.hpp | 20 +++++++++---- src/JessMain.hpp | 58 ++++++++++++++++++++---------------- test/ChunkedJournal_test.cpp | 3 ++ 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/ChunkedJournal.hpp b/src/ChunkedJournal.hpp index 0f7df85..a3382a6 100644 --- a/src/ChunkedJournal.hpp +++ b/src/ChunkedJournal.hpp @@ -57,14 +57,15 @@ class ChunkedJournal { const auto firstId = chunk.lines.front().seqid(); auto lastValidId = m_chunks.begin(); - for(auto it = m_chunks.begin(); it != m_chunks.end(); ++it) + for ( auto it = m_chunks.begin(); it != m_chunks.end(); ++it ) { - if (auto seq = it->highestIdsInChunk.find( firstId.seqnumId ); seq != it->highestIdsInChunk.end()) + if ( auto seq = it->highestIdsInChunk.find( firstId.seqnumId ); seq != it->highestIdsInChunk.end() ) { - if(firstId.seqnum > seq->second) + if ( firstId.seqnum > seq->second ) { lastValidId = it; - } else + } + else { return lastValidId; } @@ -186,7 +187,7 @@ class ChunkedJournal void seekToEof() { m_journal.seekToEof(); - m_journal.seekLinesBackward(m_uChunkSize); + m_journal.seekLinesBackward( m_uChunkSize ); loadChunkAtCurrentPosition( Adjacency::NON_ADJACENT ); // bug: this will explode if there are fewer than m_uChunkSize lines in the chunk m_uLineOffsetInChunk = m_uChunkSize - 1; @@ -230,6 +231,15 @@ class ChunkedJournal const std::span ret{ m_pCurrentChunk->lines }; return ret.subspan( m_uLineOffsetInChunk, std::min( ret.size() - m_uLineOffsetInChunk, uNumLines ) ); } + + std::string getChunkPositionString() + { + const size_t uNthChunk = std::distance( m_chunks.begin(), m_pCurrentChunk ); + const size_t uNumChunks = m_chunks.size(); + + return "chunk " + std::to_string( uNthChunk + 1 ) + "/" + std::to_string( uNumChunks ) + "; line " + std::to_string( m_uLineOffsetInChunk + 1 ) + "/" + + std::to_string( m_pCurrentChunk->lines.size() ); + } }; }// namespace jess diff --git a/src/JessMain.hpp b/src/JessMain.hpp index 48d37e6..8f6f85b 100644 --- a/src/JessMain.hpp +++ b/src/JessMain.hpp @@ -6,72 +6,80 @@ #include "NcTerminal.hpp" #include "SdJournal.hpp" -#include +namespace jess +{ -#include - -namespace jess { - -class JessMain { +class JessMain +{ NcTerminal m_rootTerminal{}; NcWindow m_rootWindow = m_rootTerminal.rootWindow(); Modeline m_modeline{ m_rootWindow }; - MainFrame m_mainFrame{m_rootWindow}; + MainFrame m_mainFrame{ m_rootWindow }; std::string m_currentCursor{}; bool m_bModelineActive{}; std::span m_currentLines{}; - ChunkedJournal m_journal{1024, 0}; + ChunkedJournal m_journal{ 1024, 0 }; public: KeyCombination getNextKey() { return m_modeline.getKeyCombination().value(); } - void scrollToBof() { + void scrollToBof() + { m_journal.seekToBof(); redrawTranslation(); } - void scrollToEof() { + void scrollToEof() + { m_journal.seekToEof(); redrawTranslation(); } - void scrollUpLine() { - m_journal.seekLines(-1); + void scrollUpLine() + { + m_journal.seekLines( -1 ); redrawTranslation(); } - void scrollDownLine() { - m_journal.seekLines(1); + void scrollDownLine() + { + m_journal.seekLines( 1 ); redrawTranslation(); } - void scrollUpPage() { - m_journal.seekLines(-static_cast(m_mainFrame.height())); + void scrollUpPage() + { + m_journal.seekLines( -static_cast( m_mainFrame.height() ) ); redrawTranslation(); } - void scrollDownPage() { - m_journal.seekLines(static_cast(m_mainFrame.height())); + void scrollDownPage() + { + m_journal.seekLines( static_cast( m_mainFrame.height() ) ); redrawTranslation(); } - void activateModeline() { + void activateModeline() + { m_bModelineActive = true; m_modeline.setActive(); m_bModelineActive = false; } private: - void redraw() { - m_mainFrame.drawLines(m_currentLines); + void redraw() + { + m_mainFrame.drawLines( m_currentLines ); m_modeline.focus(); } - void redrawTranslation() { - m_currentLines = m_journal.getLines(m_mainFrame.height()); + void redrawTranslation() + { + m_currentCursor = m_journal.getChunkPositionString(); + m_currentLines = m_journal.getLines( m_mainFrame.height() ); redraw(); displayOffset(); } - void displayOffset() { m_modeline.displayStatusString("cursor: " + m_currentCursor); } + void displayOffset() { m_modeline.displayStatusString( "cursor: " + m_currentCursor ); } }; -} // namespace jess \ No newline at end of file +}// namespace jess \ No newline at end of file diff --git a/test/ChunkedJournal_test.cpp b/test/ChunkedJournal_test.cpp index 8c27308..0b37286 100644 --- a/test/ChunkedJournal_test.cpp +++ b/test/ChunkedJournal_test.cpp @@ -261,3 +261,6 @@ TEST_CASE( "ChunkedJournal(1) load EOF" ) } } } + +// TODO: tests where chunk is smaller than entire stream +// TODO: tests where journal EOF moves