Skip to content

Commit

Permalink
[fix] show entire selected log when bottom sticky
Browse files Browse the repository at this point in the history
  • Loading branch information
robinovitch61 committed Dec 31, 2024
1 parent 6144e86 commit 89dbe36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
16 changes: 9 additions & 7 deletions dev/flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,17 @@ def exit_after_delay():
# exit_thread = threading.Thread(target=exit_after_delay, daemon=True)
# exit_thread.start()

def generate_random_text(num_words):
words = ['hello', 'world', 'test', 'random', 'text', 'words', 'generator',
'python', 'code', 'sample']
return ' '.join(random.choices(words, k=num_words))

def periodic_logger():
flag = True
while True:
logger.info("Periodic log message")
time.sleep(0.05)
logger.info(generate_random_text(100 if flag else 200))
time.sleep(0.5)
flag = not flag

# Start the periodic logging thread
# logging_thread = threading.Thread(target=periodic_logger, daemon=True)
Expand All @@ -106,11 +113,6 @@ def health():
logger.info("LAST Lorem ipsum \n\tdolor sit amet, consectetur adipiscing elit. \n\tSed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad \n\tminim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.")
return jsonify({"status": "healthy"}), 200

def generate_random_text(num_words):
words = ['hello', 'world', 'test', 'random', 'text', 'words', 'generator',
'python', 'code', 'sample']
return ' '.join(random.choices(words, k=num_words))

@app.route("/status", methods=["GET"])
def status():
logger.debug("Status endpoint called")
Expand Down
13 changes: 9 additions & 4 deletions internal/viewport/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func (m *Model[T]) SetContent(content []T) {
m.selectedItemIdx = 0
} else if stayAtBottom {
m.selectedItemIdx = max(0, len(m.allItems)-1)
m.scrollSoSelectionInView()
} else if m.maintainSelection {
// TODO: could flag when content is sorted & comparable and use binary search instead
found := false
Expand All @@ -323,10 +324,14 @@ func (m *Model[T]) SetContent(content []T) {
m.selectedItemIdx = 0
}
}
m.selectedItemIdx = clampValMinMax(m.selectedItemIdx, 0, len(m.allItems)-1)
m.scrollSoSelectionInView()
if inView := m.selectionInViewInfo(); inView.numLinesSelectionInView > 0 {
m.scrollUp(initialNumLinesAboveSelection - inView.numLinesAboveSelection)

// when staying at bottom, just want to scroll so selection in view, which is done above
if !stayAtBottom {
m.selectedItemIdx = clampValMinMax(m.selectedItemIdx, 0, len(m.allItems)-1)
m.scrollSoSelectionInView()
if inView := m.selectionInViewInfo(); inView.numLinesSelectionInView > 0 {
m.scrollUp(initialNumLinesAboveSelection - inView.numLinesAboveSelection)
}
}
}
}
Expand Down

0 comments on commit 89dbe36

Please sign in to comment.