#Multiple: Remove length of <> tags from string.len, Terminal width/height/cursor API

1 messages · Page 1 of 1 (latest)

wide elk
#

I'd love to be able to strip the length of open and closing tags like <color></color> and <mark></mark> from the overall count of a string's length as a default string function.

I also think it would be a huge QOL to be able to get the height and width of the terminal window from the shell api, as well as set the cursor/user input start to an X/Y location and get its current location.

heady breach
#

Can't you just make a parser to do that and give len without the tags? You can even add it as an extension of string so it's able to be dot notated

terse tiger
#

yeah, you can definitely do it with some pretty simple regular expression work. I can't claim credit for this specific function and I haven't expansively tested it, but this has reliably stripped style tags out of strings so I can get the "real" length.

  tags = "align|alpha|color|b|i|cspace|font|indent|line-height|line-indent|link|lowercase|uppercase|smallcaps|margin|mark|mspace|noparse|nobr|page|pos|size|space|sprite|s|u|style|sub|sup|voffset|width|link|#[0-9a-f]{3}|#[0-9a-f]{6}"
  return text.replace("<\/?(" + tags + ")(\s.*?|=.*?|.{0})>", "")
end function

While being able to specify terminal height and width and cursor position would be nice, there's at least one open suggestion for that, and it's not entirely difficult to build a system to do the output you may want within the current constraints. I'm in the middle of working on a modular, user-defined terminal-based UI, so I can say for sure it's a bit tedious, but not overly difficult.

wide elk
#

Yeah, it's not that it can't be done, it's more just quality of life suggestions than anything else. Like, there's so much in designing a UI that has to have all the boilerplate coded. I guess a parser could end up sufficient as a one and done, but even something like ANSI escape code analogs would go a long way to making life way easier for tool creators to make interactive tools that operate on more than command input.