48 lines
1.8 KiB
Swift
48 lines
1.8 KiB
Swift
import HelderCore
|
|
import SwiftUI
|
|
|
|
/// 28pt display-only bar: branch, line totals and staged/unstaged counts left; path, position, encoding, line ending and language right.
|
|
struct StatusBarView: View {
|
|
let model: WorkspaceModel
|
|
|
|
var body: some View {
|
|
let git = model.sourceControl?.state ?? .empty
|
|
let totals = git.totals
|
|
let editor = model.editor
|
|
let path = editor?.activePath
|
|
HStack(spacing: Metrics.statusBarGap) {
|
|
Text("⑂ \(git.branch)").foregroundStyle(Palette.amber).lineLimit(1)
|
|
Text("+\(totals.added)").foregroundStyle(Palette.addedText)
|
|
Text("\u{2212}\(totals.removed)").foregroundStyle(Palette.removedText)
|
|
Text("\(git.stagedCount) staged · \(git.unstagedCount) unstaged").lineLimit(1)
|
|
Spacer(minLength: 0)
|
|
if let path {
|
|
Text(path).lineLimit(1).truncationMode(.head)
|
|
.frame(maxWidth: 0.52 * model.layout.windowWidth, alignment: .trailing)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
Text("·")
|
|
Text(position(editor?.cursor, path: path))
|
|
Text("·")
|
|
}
|
|
Text("UTF-8")
|
|
Text("·")
|
|
Text("LF")
|
|
if let path {
|
|
Text("·")
|
|
Text(FileType.languageLabel(for: path)).foregroundStyle(Palette.text3)
|
|
}
|
|
}
|
|
.typeRole(Typography.meta)
|
|
.foregroundStyle(Palette.text4)
|
|
.padding(.horizontal, 14)
|
|
.frame(height: Metrics.statusBar)
|
|
.background(Palette.panel)
|
|
.hairline(.top)
|
|
}
|
|
|
|
private func position(_ cursor: Cursor?, path: String) -> String {
|
|
guard let cursor, cursor.path == path else { return "Ln 1, Col 1" }
|
|
return "Ln \(cursor.line), Col \(cursor.column)"
|
|
}
|
|
}
|