|
| 1 | +use std::cell::Cell; |
1 | 2 | use std::fmt::{Debug, Display};
|
2 | 3 | use std::io::{self, Read, Write};
|
3 | 4 | use std::sync::{Arc, Mutex, RwLock};
|
@@ -78,6 +79,19 @@ impl<'a> TermFeatures<'a> {
|
78 | 79 | is_a_color_terminal(self.0)
|
79 | 80 | }
|
80 | 81 |
|
| 82 | + #[inline] |
| 83 | + pub fn is_synchronized_output_supported(&self) -> bool { |
| 84 | + #[cfg(unix)] |
| 85 | + { |
| 86 | + supports_synchronized_output() |
| 87 | + } |
| 88 | + #[cfg(not(unix))] |
| 89 | + { |
| 90 | + // TODO |
| 91 | + false |
| 92 | + } |
| 93 | + } |
| 94 | + |
81 | 95 | /// Check if this terminal is an msys terminal.
|
82 | 96 | ///
|
83 | 97 | /// This is sometimes useful to disable features that are known to not
|
@@ -656,6 +670,42 @@ impl<'a> Read for &'a Term {
|
656 | 670 | }
|
657 | 671 | }
|
658 | 672 |
|
| 673 | +pub struct SyncGuard<'a> { |
| 674 | + term: Cell<Option<&'a Term>>, |
| 675 | +} |
| 676 | + |
| 677 | +impl<'a> SyncGuard<'a> { |
| 678 | + pub fn begin_sync(term: &'a Term) -> io::Result<Self> { |
| 679 | + let ret = if term.features().is_synchronized_output_supported() { |
| 680 | + term.write_str("\x1b[?2026h")?; |
| 681 | + Some(term) |
| 682 | + } else { |
| 683 | + None |
| 684 | + }; |
| 685 | + |
| 686 | + Ok(Self { |
| 687 | + term: Cell::new(ret), |
| 688 | + }) |
| 689 | + } |
| 690 | + |
| 691 | + pub fn finish_sync(self) -> io::Result<()> { |
| 692 | + self.finish_sync_inner() |
| 693 | + } |
| 694 | + |
| 695 | + fn finish_sync_inner(&self) -> io::Result<()> { |
| 696 | + if let Some(term) = self.term.take() { |
| 697 | + term.write_str("\x1b[?2026l")?; |
| 698 | + } |
| 699 | + Ok(()) |
| 700 | + } |
| 701 | +} |
| 702 | + |
| 703 | +impl Drop for SyncGuard<'_> { |
| 704 | + fn drop(&mut self) { |
| 705 | + let _ = self.finish_sync_inner(); |
| 706 | + } |
| 707 | +} |
| 708 | + |
659 | 709 | #[cfg(all(unix, not(target_arch = "wasm32")))]
|
660 | 710 | pub use crate::unix_term::*;
|
661 | 711 | #[cfg(target_arch = "wasm32")]
|
|
0 commit comments