SwiftLI

SwiftLI 是一个旨在用类似 SwiftUI 的方式在 Swift 中编写命令行显示的库,它的灵感来自 SwiftUI 和 Ignite。
正如 SwiftUI 是一个使在 Swift 中构建 GUI 变得容易的库一样,SwiftLI 旨在使在 Swift 中构建 CLI 变得容易。

要求

要使用此库,需要以下环境。

Twitter: @IroIro1234work

演示

该库包含一个命令行工具,允许您验证其运行。 请使用以下方法以及源代码来检查该命令行工具。

使用 CMake

  1. 下载此项目文件
  2. 打开一个终端
  3. 输入以下命令
cd <Path to this project>
make install

使用 Homebrew

  1. 在终端中输入以下命令
brew install kc-2001ms/tap/sclt

用法

您可以通过如下构建您的代码来轻松构建命令行 CUI

import ArgumentParser
import SwiftLI

struct TextCommand: ParsableCommand {
    static var configuration = CommandConfiguration(
        commandName: "text",
        abstract: "Display of Text structure",
        discussion: """
        Command to check the display of Text structure
        """,
        version: "0.0.2",
        shouldDisplay: true,
        helpNames: [.long, .short]
    )
    
    mutating func run() {
        let group = Group {
            Text("Text View")
                .background(Color.white)
                .forgroundColor(Color.blue)
                .bold()
                .newLine()
            
            Group {
                Group {
                    Text("Text.forgroundColor(_ color: Color)")
                        .forgroundColor(.red)
                    
                    Spacer()
                    
                    Text(".red")
                        .fontWeight(.thin)
                        .forgroundColor(.red)
                }
                .newLine()
                
                Group {
                    Text("Text.backgroundColor(_ color: Color)")
                        .background(.red)
                    
                    Spacer()
                    
                    Text(".red")
                        .fontWeight(.thin)
                        .forgroundColor(.red)
                }
                .newLine()
                
                Text("Text.bold()")
                    .bold()
                    .newLine()
                
                Group {
                    Text("Text.bold(_ isActive: Bool)")
                        .bold(false)
                    
                    Spacer()
                    
                    Text("false")
                        .fontWeight(.thin)
                        .forgroundColor(.red)
                }
                .newLine()
                
                Group {
                    Text("Text.fontWeight(_ weight: Weight)")
                        .fontWeight(.thin)
                    
                    Spacer()
                    
                    Text(".thin")
                        .fontWeight(.thin)
                        .forgroundColor(.red)
                }
                .newLine()
                
                Text("Text.italic()")
                    .italic()
                    .newLine()
                
                Group {
                    Text("Text.italic(_ isActive: Bool)")
                        .italic(false)
                    
                    Spacer()
                    
                    Text("false")
                        .fontWeight(.thin)
                        .forgroundColor(.red)
                }
                .newLine()
                
                Text("Text.underline()")
                    .underline()
                    .newLine()
                
                Group {
                    Text("Text.underline(_ isActive: Bool)")
                        .underline(false)
                    
                    Spacer()
                    
                    Text("false")
                        .fontWeight(.thin)
                        .forgroundColor(.red)
                }
                .newLine()
                
                Group {
                    Text("Text.blink(_ style: BlinkStyle)")
                        .blink(.default)
                    
                    Spacer()
                    
                    Text(".default")
                        .fontWeight(.thin)
                        .forgroundColor(.red)
                }
                .newLine()
                
                Text("Text.hidden()")
                    .hidden()
                    .newLine()
                
                Group {
                    Text("Text.hidden(_ isActive: Bool)")
                        .hidden(false)
                    
                    Spacer()
                    
                    Text("false")
                        .fontWeight(.thin)
                        .forgroundColor(.red)
                }
                .newLine()
                
                Text("Text.strikethrough()")
                    .strikethrough()
                    .newLine()
                
                Group {
                    Text("Text.strikethrough(_ isActive: Bool)")
                        .strikethrough(false)
                    
                    Spacer()
                    
                    Text("false")
                        .fontWeight(.thin)
                        .forgroundColor(.red)
                }
                .newLine()
            }
        }
        
        group.render()
    }
}

安装

将以下文件添加到 Package.swift 文件以供使用。 有关更多信息,请访问 swift.org

    dependencies: [
        // Add this code
        .package(url: "https://github.com/KC-2001MS/SwiftLI.git", from: "0.3.0"),
    ],

Swift-DocC

Swift-DocC 目前正在实施中。

文档

贡献

如果您想做出贡献,请参阅 CONTRIBUTING.md

许可

SwiftLI

支持

如果您想向该项目捐款,请点击此处。 您给予的款项将用于提高我的编程技能和维护应用程序。
Buy Me A Coffee
通过 PayPal 付款

作者

Keisuke Chinone