Skip to content

Instantly share code, notes, and snippets.

@andscoop
Created February 17, 2018 14:10
Show Gist options
  • Save andscoop/874ff042a28ca5aaa06426a58aacaf83 to your computer and use it in GitHub Desktop.
Save andscoop/874ff042a28ca5aaa06426a58aacaf83 to your computer and use it in GitHub Desktop.
fix nice-editor (ne) backspace issue
KEY 0x7f BS
KEY 0x115 DC
@utoddl
Copy link

utoddl commented Oct 20, 2019

You have eloquently described a long-standing bug with ncurses, not ne. I hardly think the solution is for every application to ignore the terminfo information for this one case rather than to fix the broken terminal definitions.

@craigbarnes
Copy link

craigbarnes commented Oct 20, 2019

I hardly think the solution is for every application to ignore the terminfo information

ncurses may be partly to blame, but there's a solution that fixes the problem without many practical downsides. Since ^H and ^? are both control keys, you can just treat them like other control keys (i.e. not as "special" keys) and then just bind both to erase by default. I don't know if that's compatible with the ne key binding model but it's what I do in dte. In theory, it could cause the inverse of the current problem, but the terminals where that could happen all seem like relics.

@vigna
Copy link

vigna commented Oct 20, 2019

Well, in the last 26 (!) years we tried to Do The Right Thing. At this point, I think we should continue to Do The Right Thing. Maybe it's too much to hope that terminal implementors and terminfo database maintainers fix this in the right way, but for the time being it seems to be a very minor nuisance.

@utoddl
Copy link

utoddl commented Oct 21, 2019

@craigbarnes If I'm reading your code correctly (dte/terminfo.c), you're using "kdch1" from terminfo as Delete, but that code doesn't even attempt to get anything from terminfo for backspace, just assuming it's either ^H or ^?. I can see several reasons for taking that approach: (1) it appears to work pretty much everywhere, (2) a lot of otherwise useful terminfo files are just dead wrong wrt backspace anyway, and (3) everybody else does it because of 1 and 2. I'd really like ne to "just work", but I'd like it to be because the terminfos are right, not because we're intentionally ignoring it. For a key as fundamental as backspace, I can't understand how so many terminfo files can be so wrong, nor why it seems impossible to get them fixed.

Ignoring short term patches and workarounds for the moment, I'm asking you -- as you've clearly thought about the problem and have some skin in the game so to speak with your own editor which has to deal with this -- what would have to happen to get the backspace key definition fixed in some significant portion of the terminfo definitions where it's currently broken? I really want to know.

I can imagine a simple interactive program that asks you to press different keys and it tells you where your terminfo is right/wrong, maybe even generating either a patch or new terminfo definition based on the results. I don't know if that would help, though, because you'd have to get someone to run it who's in a position to do something about the problems it might turn up.

@craigbarnes
Copy link

craigbarnes commented Oct 21, 2019

For a key as fundamental as backspace, I can't understand how so many terminfo files can be so wrong, nor why it seems impossible to get them fixed.

Yeah, it's unfortunate that it's ended up that way, but I can understand how it happened. No terminal developer wants to wait until every distro picks up their custom terminfo entry, so they just abuse the xterm one. There are countless other problems caused by this, but fortunately text editors don't typically run into them.

... what would have to happen to get the backspace key definition fixed in some significant portion of the terminfo definitions where it's currently broken?

Probably for every terminal emulator that claims to be xterm to start using the same key code. Or at least the ones people still use.

I can imagine a simple interactive program that asks you to press different keys and it tells you where your terminfo is right/wrong

The xterm/ncurses maintainer has something like that at https://invisible-island.net/ncurses/tack.html.

I don't know if that would help, though, because you'd have to get someone to run it who's in a position to do something about the problems it might turn up.

I'm at the stage where I just assume that anything not part of the basic common subset of features will be completely messed up by at least one terminal. Unfortunately, people actually use such terminals -- so the best thing you can do is stay within that small set of features and just take a pragmatic approach to things like the backspace issue.

@ortonomy
Copy link

@andscoop -- you wonderfuk bastard. this has been annoying the hell out of me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment