Skip to content
Permalink
Browse files

Add --no-stdin to iina-cli

  • Loading branch information...
lhc70000 committed Feb 27, 2019
1 parent 319ea85 commit b6edcf3dfc7fd9a6a0d79ae815e82b96921fc365
Showing with 30 additions and 10 deletions.
  1. +30 −10 iina-cli/main.swift
@@ -29,13 +29,6 @@ guard FileManager.default.fileExists(atPath: iinaPath) else {
let task = Process()
task.launchPath = iinaPath

guard let stdin = InputStream(fileAtPath: "/dev/stdin") else {
print("Cannot open stdin.")
exit(1)
}
stdin.open()

let isStdin = stdin.hasBytesAvailable
var keepRunning = false

// Check arguments
@@ -53,10 +46,11 @@ if userArgs.contains(where: { $0 == "--help" || $0 == "-h" }) {
Example: --mpv-volume=20 --mpv-resume-playback=no
--separate-windows | -w:
Open all files in separate windows.
--stdin:
--stdin, --no-stdin:
You may also pipe to stdin directly. Sometimes iina-cli can detect whether
stdin has file, but sometimes not. Therefore it's recommended to always
supply this argument when piping to iina.
supply --stdin when piping to iina, and --no-stdin when you are not intend
to use stdin.
--keep-running:
Normally iina-cli launches IINA and quits immediately. Supply this option
if you would like to keep it running until the main application exits.
@@ -72,6 +66,30 @@ if userArgs.contains(where: { $0 == "--help" || $0 == "-h" }) {
exit(0)
}

var isStdin = false
var userSpecifiedStdin = false

for arg in userArgs {
if arg == "--stdin" {
isStdin = true
userSpecifiedStdin = true
} else if arg == "--no-stdin" {
isStdin = false
userSpecifiedStdin = true
} else if arg == "--" {
break
}
}

if (!userSpecifiedStdin) {
guard let stdin = InputStream(fileAtPath: "/dev/stdin") else {
print("Cannot open stdin.")
exit(1)
}
stdin.open()
isStdin = stdin.hasBytesAvailable
}

if let dashIndex = userArgs.index(of: "--") {
userArgs.remove(at: dashIndex)
for i in dashIndex..<userArgs.count {
@@ -107,7 +125,9 @@ userArgs = userArgs.map { arg in
if isStdin {
task.standardInput = FileHandle.standardInput
task.standardOutput = FileHandle.standardOutput
userArgs.insert("--stdin", at: 0)
if !userSpecifiedStdin {
userArgs.insert("--stdin", at: 0)
}
} else {
task.standardOutput = nil
task.standardError = nil

0 comments on commit b6edcf3

Please sign in to comment.
You can’t perform that action at this time.