mirror of
https://github.com/phranck/TUIkit.git
synced 2026-05-21 09:50:35 +00:00
e214215610
- Migrate 20 Equatable conformances across 17 files from nonisolated + MainActor.assumeIsolated to @preconcurrency Equatable (SE-0423) - Remove unnecessary import Foundation from 29 source files - Extract TextFieldHandler clipboard ops into TextFieldHandler+Clipboard.swift - Extract RenderContext into RenderContext.swift (Renderable.swift 553 -> 279 lines) - Extract ANSIColor enum into ANSIColor.swift (Color.swift 600 -> 533 lines) - Add deprecation timeline note for progressBarStyle(_:) - Migrate test usages from progressBarStyle to trackStyle
40 lines
1.3 KiB
Swift
40 lines
1.3 KiB
Swift
// 🖥️ TUIKit — Terminal UI Kit for Swift
|
||
// ScrollIndicator.swift
|
||
//
|
||
// Created by LAYERED.work
|
||
// License: MIT
|
||
|
||
|
||
// MARK: - Scroll Direction
|
||
|
||
/// The direction of a scroll indicator arrow.
|
||
enum ScrollDirection {
|
||
case up, down
|
||
}
|
||
|
||
// MARK: - Scroll Indicator Rendering
|
||
|
||
/// Renders a centered scroll indicator line with an arrow and label.
|
||
///
|
||
/// Used by `_ListCore` and `_TableCore` to show "more above" / "more below"
|
||
/// indicators when content extends beyond the visible viewport.
|
||
///
|
||
/// - Parameters:
|
||
/// - direction: Whether the indicator points up or down.
|
||
/// - width: The total width available for the indicator line.
|
||
/// - palette: The color palette for styling.
|
||
/// - Returns: A styled string with a centered scroll indicator.
|
||
@MainActor
|
||
func renderScrollIndicator(direction: ScrollDirection, width: Int, palette: any Palette) -> String {
|
||
let arrow = direction == .up ? "▲" : "▼"
|
||
let label = direction == .up ? " more above " : " more below "
|
||
|
||
let styledArrow = ANSIRenderer.colorize(arrow, foreground: palette.foregroundTertiary)
|
||
let styledLabel = ANSIRenderer.colorize(label, foreground: palette.foregroundTertiary)
|
||
|
||
let indicatorWidth = 1 + label.count
|
||
let padding = max(0, (width - indicatorWidth) / 2)
|
||
|
||
return String(repeating: " ", count: padding) + styledArrow + styledLabel
|
||
}
|