Skip to content

Commit

Permalink
show chunk position in modeline
Browse files Browse the repository at this point in the history
  • Loading branch information
bastidest committed Nov 12, 2023
1 parent b121f32 commit 06a128a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
20 changes: 15 additions & 5 deletions src/ChunkedJournal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
58 changes: 33 additions & 25 deletions src/JessMain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,80 @@
#include "NcTerminal.hpp"
#include "SdJournal.hpp"

#include <systemd/sd-journal.h>
namespace jess
{

#include <vector>

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<SdLine> m_currentLines{};
ChunkedJournal<SdJournal> m_journal{1024, 0};
ChunkedJournal<SdJournal> 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<int64_t>(m_mainFrame.height()));
void scrollUpPage()
{
m_journal.seekLines( -static_cast<int64_t>( m_mainFrame.height() ) );
redrawTranslation();
}

void scrollDownPage() {
m_journal.seekLines(static_cast<int64_t>(m_mainFrame.height()));
void scrollDownPage()
{
m_journal.seekLines( static_cast<int64_t>( 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
}// namespace jess
3 changes: 3 additions & 0 deletions test/ChunkedJournal_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 06a128a

Please sign in to comment.