Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions CodeEdit/Documents/WorkspaceCodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ struct WorkspaceCodeFileView: View {
var windowController: NSWindowController
@ObservedObject var workspace: WorkspaceDocument

@ViewBuilder var codeView: some View {
@ViewBuilder
var codeView: some View {
if let item = workspace.selectionState.openFileItems.first(where: { file in
if file.id == workspace.selectionState.selectedId {
print("Item loaded is: ", file.url)
Expand All @@ -30,11 +31,6 @@ struct WorkspaceCodeFileView: View {
BreadcrumbsView(item, workspace: workspace)
}
}
.safeAreaInset(edge: .bottom) {
if let url = workspace.fileURL {
StatusBarView(workspaceURL: url)
}
}
} else {
Text("CodeEdit cannot open this file because its file type is not supported.")
}
Expand All @@ -44,12 +40,7 @@ struct WorkspaceCodeFileView: View {
}

var body: some View {
HSplitView {
codeView
.frame(maxWidth: .infinity, maxHeight: .infinity)

InspectorSidebar(workspace: workspace, windowController: windowController)
.frame(minWidth: 250, maxWidth: 250, maxHeight: .infinity)
}
codeView
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
2 changes: 1 addition & 1 deletion CodeEdit/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct SettingsView: View {
}
}
.padding()
.frame(width: 450, height: 200)
.frame(width: 600, height: 250)
}
}

Expand Down
34 changes: 34 additions & 0 deletions CodeEdit/Settings/TerminalSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct TerminalSettingsView: View {
@AppStorage(TerminalFontName.storageKey) var terminalFontName: String = TerminalFontName.default
@AppStorage(TerminalFontSize.storageKey) var terminalFontSize: Int = TerminalFontSize.default

@StateObject private var colors = AnsiColors.shared

var body: some View {
Form {
Picker("Terminal Shell".localized(), selection: $shellType) {
Expand All @@ -37,9 +39,41 @@ struct TerminalSettingsView: View {
FontPicker("\(terminalFontName) \(terminalFontSize)", name: $terminalFontName, size: $terminalFontSize)
}
}
Divider()
Section {
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 0) {
ansiColorPicker($colors.colors[0])
ansiColorPicker($colors.colors[1])
ansiColorPicker($colors.colors[2])
ansiColorPicker($colors.colors[3])
ansiColorPicker($colors.colors[4])
ansiColorPicker($colors.colors[5])
ansiColorPicker($colors.colors[6])
ansiColorPicker($colors.colors[7])
Text("Normal").padding(.leading, 4)
}
HStack(spacing: 0) {
ansiColorPicker($colors.colors[8])
ansiColorPicker($colors.colors[9])
ansiColorPicker($colors.colors[10])
ansiColorPicker($colors.colors[11])
ansiColorPicker($colors.colors[12])
ansiColorPicker($colors.colors[13])
ansiColorPicker($colors.colors[14])
ansiColorPicker($colors.colors[15])
Text("Bright").padding(.leading, 4)
}
}
}
}
.padding()
}

private func ansiColorPicker(_ color: Binding<Color>) -> some View {
ColorPicker(selection: color, supportsOpacity: false) { }
.labelsHidden()
}
}

struct TerminalSettingsView_Previews: PreviewProvider {
Expand Down
25 changes: 21 additions & 4 deletions CodeEdit/WorkspaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import WorkspaceClient
import StatusBar

struct WorkspaceView: View {
init(windowController: NSWindowController, workspace: WorkspaceDocument) {
Expand All @@ -28,10 +29,7 @@ struct WorkspaceView: View {
var body: some View {
NavigationView {
if workspace.workspaceClient != nil {
LeadingSidebar(workspace: workspace, windowController: windowController)
.frame(minWidth: 250)
WorkspaceCodeFileView(windowController: windowController,
workspace: workspace)
content
} else {
EmptyView()
}
Expand All @@ -49,6 +47,25 @@ struct WorkspaceView: View {
}
}
}

@ViewBuilder
private var content: some View {
LeadingSidebar(workspace: workspace, windowController: windowController)
.frame(minWidth: 250)
HSplitView {
ZStack {
WorkspaceCodeFileView(windowController: windowController,
workspace: workspace)
}
.safeAreaInset(edge: .bottom) {
if let url = workspace.fileURL {
StatusBarView(workspaceURL: url)
}
}
InspectorSidebar(workspace: workspace, windowController: windowController)
.frame(minWidth: 250, maxWidth: 250, maxHeight: .infinity)
}
}
}

struct WorkspaceView_Previews: PreviewProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class StatusBarModel: ObservableObject {
/// A GitClient instance
private (set) var gitClient: GitClient

/// The base URL of the workspace
private (set) var workspaceURL: URL

/// The maximum height of the drawer
Expand All @@ -62,8 +63,8 @@ public class StatusBarModel: ObservableObject {
// TODO: Add @Published vars for indentation, encoding, linebreak

/// Initialize with a GitClient
/// - Parameter gitClient: a GitClient

/// - Parameter workspaceURL: the current workspace URL
///
public init(workspaceURL: URL) {
self.workspaceURL = workspaceURL
self.gitClient = GitClient.default(directoryURL: workspaceURL)
Expand All @@ -72,5 +73,9 @@ public class StatusBarModel: ObservableObject {
} else {
self.selectedBranch = gitClient.getCurrentBranchName()
}
StatusBarModel.shared = self
}

/// shared instance that persists though session
public static var shared: StatusBarModel?
}
12 changes: 10 additions & 2 deletions CodeEditModules/Modules/StatusBar/src/StatusBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ public struct StatusBarView: View {
/// Initialize with GitClient
/// - Parameter gitClient: a GitClient
public init(workspaceURL: URL) {
self.model = .init(workspaceURL: workspaceURL)
self.model = .shared ?? .init(workspaceURL: workspaceURL)
}

public var body: some View {
VStack(spacing: 0) {
bar
StatusBarDrawer(model: model)
if model.isExpanded {
StatusBarDrawer(model: model)
.transition(.move(edge: .bottom))
}
}
// removes weird light gray bar above when in light mode
.padding(.top, -8) // (comment out to make it look normal in preview)
Expand Down Expand Up @@ -63,6 +66,11 @@ public struct StatusBarView: View {
.overlay(alignment: .top) {
Divider()
}
.overlay(alignment: .bottom) {
if model.isExpanded {
Divider()
}
}
.frame(height: 32)
.gesture(dragGesture)
.onHover { isHovering($0, isDragging: model.isDragging, cursor: .resizeUpDown) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal struct StatusBarDrawer: View {
}

internal var body: some View {
// Rectangle()
TerminalEmulatorView(url: model.workspaceURL)
.frame(minHeight: 0,
idealHeight: model.isExpanded ? model.currentHeight : 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// SwiftTerm+Color+Init.swift
//
//
// Created by Lukas Pistrol on 24.03.22.
//

import SwiftTerm

internal extension SwiftTerm.Color {
/// 0.0-1.0
convenience init(dRed red: Double, green: Double, blue: Double) {
let multiplier: Double = 65535
self.init(red: UInt16(red * multiplier),
green: UInt16(green * multiplier),
blue: UInt16(blue * multiplier))
}

/// 0-255
convenience init(iRed red: UInt8, green: UInt8, blue: UInt8) {
let divisor: Double = 255
self.init(dRed: Double(red) / divisor,
green: Double(green) / divisor,
blue: Double(blue) / divisor)
}

/// 0x000000 - 0xFFFFFF
convenience init(hex: Int) {
let red = UInt8((hex >> 16) & 0xFF)
let green = UInt8((hex >> 8) & 0xFF)
let blue = UInt8(hex & 0xFF)
self.init(iRed: red, green: green, blue: blue)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// File.swift
//
//
// Created by Lukas Pistrol on 23.03.22.
//

import SwiftUI

public class AnsiColors: ObservableObject {
// public static let `default` =
public static let storageKey: String = "ANSIColors"
public static let shared: AnsiColors = .init()

public init() {
guard let loadColors = UserDefaults.standard.object(forKey: Self.storageKey) as? [Int] else {
colors.append(Color(red: 0.000, green: 0.000, blue: 0.000))
colors.append(Color(red: 0.600, green: 0.000, blue: 0.000))
colors.append(Color(red: 0.000, green: 0.651, blue: 0.004))
colors.append(Color(red: 0.600, green: 0.600, blue: 0.000))
colors.append(Color(red: 0.000, green: 0.031, blue: 0.702))
colors.append(Color(red: 0.702, green: 0.020, blue: 0.702))
colors.append(Color(red: 0.000, green: 0.647, blue: 0.702))
colors.append(Color(red: 0.749, green: 0.749, blue: 0.749))
colors.append(Color(red: 0.400, green: 0.400, blue: 0.400))
colors.append(Color(red: 0.902, green: 0.000, blue: 0.004))
colors.append(Color(red: 0.004, green: 0.851, blue: 0.000))
colors.append(Color(red: 0.902, green: 0.898, blue: 0.012))
colors.append(Color(red: 0.000, green: 0.063, blue: 1.000))
colors.append(Color(red: 0.902, green: 0.035, blue: 0.902))
colors.append(Color(red: 0.008, green: 0.902, blue: 0.898))
colors.append(Color(red: 0.902, green: 0.902, blue: 0.902))
return
}
print("loaded")
self.mappedColors = loadColors
}

@Published public var mappedColors: [Int] = [] {
didSet {
UserDefaults.standard.set(mappedColors, forKey: AnsiColors.storageKey)
print("saved")
}
}

public var colors: [Color] {
get {
let mapped = self.mappedColors.map { Color(hex: $0) }
return mapped
}
set {
self.mappedColors = newValue.map { $0.hex }
}

}
}

public extension Color {
init(hex: Int) {
let red = (hex >> 16) & 0xFF
let green = (hex >> 8) & 0xFF
let blue = hex & 0xFF
self.init(.sRGB, red: Double(red) / 255, green: Double(green) / 255, blue: Double(blue) / 255, opacity: 1)
}

var hex: Int {
guard let components = cgColor?.components, components.count >= 3 else { return 0 }

let red = Int(components[0] * 255) << 16
let green = Int(components[1] * 255) << 8
let blue = Int(components[2] * 255)

return red | green | blue
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// File.swift
//
//
// Created by Lukas Pistrol on 24.03.22.
//

import SwiftUI
import SwiftTerm

public extension TerminalEmulatorView {
class Coordinator: NSObject, LocalProcessTerminalViewDelegate {

public override init() {}

public func hostCurrentDirectoryUpdate(source: TerminalView, directory: String?) {}

public func sizeChanged(source: LocalProcessTerminalView, newCols: Int, newRows: Int) {}

public func setTerminalTitle(source: LocalProcessTerminalView, title: String) {}

public func processTerminated(source: TerminalView, exitCode: Int32?) {
guard let exitCode = exitCode else {
return
}
source.feed(text: "Exit code: \(exitCode)\n\r\n")
source.feed(text: "To open a new session close and reopen the terminal drawer")
TerminalEmulatorView.lastTerminal = nil
}
}
}
Loading