Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab characters not shown in TUI #305

Closed
osa1 opened this issue Feb 5, 2021 · 5 comments
Closed

Tab characters not shown in TUI #305

osa1 opened this issue Feb 5, 2021 · 5 comments
Labels

Comments

@osa1
Copy link
Owner

osa1 commented Feb 5, 2021

@Kabouik reported on IRC that tiny doesn't show tab characters. Haven't check the code yet but I wouldn't be surprised if we just completely ignore tab characters in termbox.

@osa1 osa1 added the bug label Feb 5, 2021
@Kabouik
Copy link

Kabouik commented Feb 5, 2021

Thanks for opening the issue @osa1. To illustrate the problem, if I use $EDITOR (Kakoune in my case) to post this in Tiny:

<div>
	<p>
		aaa
	</p>
	<p>
		bbb
	</p>
</div>

<div>
    <p>
        Let's see if it's related to my editor using \t instead of spaces.
    </p>
</div>

I get this:

Screenshot_20210205_003

And it seems others using other clients see the indentation even when I use only tabs, but they didn't tell me which client they were using. @sarnold in the #tiny channel showed that irssi users see that:

irssi in tmux in mosh in urxvt. The capital Is are inverse video tabs.

Fri 05 14:58:53 < Kabouik> <div>
Fri 05 14:58:53 < Kabouik> I<p>
Fri 05 14:58:53 < Kabouik> IIaaa
Fri 05 14:58:55 < Kabouik> I</p>
Fri 05 14:58:55 < Kabouik> I<p>
Fri 05 14:58:57 < Kabouik> IIbbb
Fri 05 14:58:57 < Kabouik> I</p>
Fri 05 14:58:59 < Kabouik> </div>
Fri 05 14:58:59 < Kabouik>  
Fri 05 14:59:01 < Kabouik> <div>
Fri 05 14:59:01 < Kabouik>     <p>
Fri 05 14:59:03 < Kabouik>         Let's see if it's related to my editor using \t instead of spaces.
Fri 05 14:59:03 < Kabouik>     </p>
Fri 05 14:59:05 < Kabouik> </div>
Fri 05 14:59:33 < Kabouik> Yeah, I can see space-identation, not tab-identation
Fri 05 14:59:48 < Kabouik> But apparently others using other IRC clients could see tab-identation too

@osa1
Copy link
Owner Author

osa1 commented Feb 6, 2021

termbox's tab handling is fine. Here's an example:

use term_input::{Event, Input, Key};
use termbox_simple::*;
use tokio::stream::StreamExt;

fn main() {
    let mut tui = Termbox::init().unwrap();

    draw(&mut tui);

    let runtime = tokio::runtime::Builder::new_current_thread()
        .enable_all()
        .build()
        .unwrap();
    let local = tokio::task::LocalSet::new();

    local.block_on(&runtime, async move {
        let mut input = Input::new();
        while let Some(mb_ev) = input.next().await {
            match mb_ev {
                Err(_) => {}
                Ok(Event::Key(Key::Esc)) => {
                    return;
                }
                Ok(_) => {}
            }
            draw(&mut tui);
        }
    });
}

fn draw(tui: &mut Termbox) {
    tui.clear();

    tui.change_cell(0, 0, '\t', 0, 1);
    tui.change_cell(1, 0, 'x', 0, 1);

    tui.present();
}

When I run this I see

        x

so the tab is rendered as 8 spaces.

@osa1
Copy link
Owner Author

osa1 commented Feb 6, 2021

This must be where we drop the tab character, as it's considered a "control" character:

/// Translate IRC color codes using the callback, and remove ASCII control chars from the input.
pub(crate) fn translate_irc_control_chars(
str: &str,
push_color: fn(ret: &mut String, fg: u8, bg: Option<u8>),
) -> String {
let mut ret = String::with_capacity(str.len());
let mut iter = str.chars().peekable();
while let Some(char) = iter.next() {
if char == '\x03' {
match parse_color_code(&mut iter) {
None => {
// just skip the control char
}
Some(fg) => {
if let Some(char) = iter.peek().cloned() {
if char == ',' {
iter.next(); // consume ','
match parse_color_code(&mut iter) {
None => {
// comma was not part of the color code,
// add it to the new string
push_color(&mut ret, fg, None);
ret.push(char);
}
Some(bg) => {
push_color(&mut ret, fg, Some(bg));
}
}
} else {
push_color(&mut ret, fg, None);
}
} else {
push_color(&mut ret, fg, None);
}
}
}
} else if !char.is_ascii_control() {
ret.push(char);
}
}
ret
}

@osa1 osa1 closed this as completed in 1ba1163 Feb 6, 2021
@osa1
Copy link
Owner Author

osa1 commented Feb 6, 2021

Fixed.

Note that we don't handle entering wide characters (characters that take more than one row on screen, e.g. ) in the input widget yet. I'll create another issue for that.

@osa1
Copy link
Owner Author

osa1 commented Feb 6, 2021

Note that we don't handle entering wide characters (characters that take more than one row on screen, e.g. H) in the input widget yet. I'll create another issue for that.

Tracked in #306.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants