Repository navigation
Modern Tui TuiTruncate
Home › Terminal TUI Library › Unicode Width › TuiTruncate
Cuts a string to fit a number of columns, ending in "..." unless you pass "".
TuiTruncate( byref s as ustring, byval maxCols as int32, byref ellipsis as ustring = "..." ) as ustringCuts a string to fit a column budget. THE ELLIPSIS DEFAULTS TO "..." and is itself counted, so the result never exceeds maxCols -- pass an empty string for a hard cut. It never splits a wide glyph in half, and when even the ellipsis will not fit, the ELLIPSIS is truncated rather than the budget exceeded.
#import "std/tui"
using tui
print TuiTruncate( "abcdefgh", 5 ) '' ab... -- the ellipsis
'' DEFAULTS to "..." and
'' counts toward the 5
print TuiTruncate( "abcdefgh", 5, "" ) '' abcde -- a hard cut
print TuiTruncate( "abc", 10 ) '' abc -- shorter is untouched
'' two wide glyphs in a 3-column budget: there is no room for a glyph AND the
'' ellipsis, so only the ellipsis survives -- and it still fits exactly
print TuiStringWidth( TuiTruncate( wchr( &h4E2D ) & wchr( &h4E2D ), 3 ) ) '' 3TuiCharWidth · TuiStringWidth · TuiWrap · TuiSetAmbiguousWide · TuiAmbiguousWide
Library: Terminal TUI Library
Category: Terminal TUI Library
Documented under: Unicode Width
Working examples: hello.tiko · form.tiko · dashboard.tiko
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing