Skip to content

Commit

Permalink
[tui] Incorporate OutputDevice into main_event_loop
Browse files Browse the repository at this point in the history
- Replace exec_render_op! with:
  - queue_render_op!,
  - flush_now!,
  - disable_raw_mode_now!, enable_raw_mode_now!
- Migrate RawMode
  • Loading branch information
nazmulidris committed Oct 19, 2024
1 parent 0f35ee0 commit 416da41
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 172 deletions.
1 change: 0 additions & 1 deletion test_fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@

// Attach sources.
pub mod async_stream_fixtures;
pub mod output_device_fixtures;
pub mod stdout_fixtures;

// Re-export.
Expand Down
23 changes: 23 additions & 0 deletions test_fixtures/src/stdout_fixtures/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 R3BL LLC
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Attach.
pub mod output_device_ext;
pub mod stdout_mock;

// Re-export.
pub use stdout_mock::*;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ use std::{io::{Result, Write},
use r3bl_core::StdMutex;
use strip_ansi_escapes::strip;

/// You can safely clone this struct, since it only contains an `Arc<StdMutex<Vec<u8>>>`. The
/// inner `buffer` will not be cloned, just the [Arc] will be cloned.
/// You can safely clone this struct, since it only contains an `Arc<StdMutex<Vec<u8>>>`.
/// The inner `buffer` will not be cloned, just the [Arc] will be cloned.
///
/// The main constructors are:
/// - [StdoutMock::default]
/// - [StdoutMock::new]
/// - [StdoutMock::new_output_device]
#[derive(Clone)]
pub struct StdoutMock {
pub buffer: Arc<StdMutex<Vec<u8>>>,
Expand All @@ -36,6 +41,10 @@ impl Default for StdoutMock {
}
}

impl StdoutMock {
pub fn new() -> Self { Self::default() }
}

impl StdoutMock {
pub fn get_copy_of_buffer(&self) -> Vec<u8> { self.buffer.lock().unwrap().clone() }

Expand Down
2 changes: 1 addition & 1 deletion tui/examples/demo/ex_pitch/slide1.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
│ ❯ 🚀 productivity │
│ ❯ 🌍 efficiency │
│ ❯ 📖 knowledge capture & sharing │
│ ❯ 🛣️ workflow management │
│ ❯ ⚗️ workflow management │
╰────────────────────────────────────╯
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use r3bl_core::{call_if_true,
ch,
position,
ChUnit,
LockedOutputDevice,
Size,
TuiStyle,
UnicodeString,
Expand All @@ -39,19 +40,25 @@ use crate::{render_ops,
pub struct OffscreenBufferPaintImplCrossterm;

impl OffscreenBufferPaint for OffscreenBufferPaintImplCrossterm {
fn paint(&mut self, render_ops: RenderOps, flush_kind: FlushKind, window_size: Size) {
fn paint(
&mut self,
render_ops: RenderOps,
flush_kind: FlushKind,
window_size: Size,
locked_output_device: LockedOutputDevice<'_>,
) {
let mut skip_flush = false;

if let FlushKind::ClearBeforeFlush = flush_kind {
RenderOp::default().clear_before_flush();
RenderOp::default().clear_before_flush(locked_output_device);
}

// Execute each RenderOp.
render_ops.execute_all(&mut skip_flush, window_size);
render_ops.execute_all(&mut skip_flush, window_size, locked_output_device);

// Flush everything to the terminal.
if !skip_flush {
RenderOp::default().flush()
RenderOp::default().flush(locked_output_device)
};

// Debug output.
Expand All @@ -62,15 +69,20 @@ impl OffscreenBufferPaint for OffscreenBufferPaintImplCrossterm {
});
}

fn paint_diff(&mut self, render_ops: RenderOps, window_size: Size) {
fn paint_diff(
&mut self,
render_ops: RenderOps,
window_size: Size,
locked_output_device: LockedOutputDevice<'_>,
) {
let mut skip_flush = false;

// Execute each RenderOp.
render_ops.execute_all(&mut skip_flush, window_size);
render_ops.execute_all(&mut skip_flush, window_size, locked_output_device);

// Flush everything to the terminal.
if !skip_flush {
RenderOp::default().flush()
RenderOp::default().flush(locked_output_device)
};

// Debug output.
Expand Down
Loading

0 comments on commit 416da41

Please sign in to comment.