-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace golang.org/x/term with golang.org/x/sys/unix
A subsequent commit will use this to ensure that the user can still interact with the image download prompt while 'skopeo inspect' fetches the image size from the remote registry. To do this, at some point, the terminal device will be put into non-canonical mode input and the echoing of input characters will be disabled to retain full control of the cursor position. Unfortunately, this will require access to the full termios(3) struct that isn't given by golang.org/x/term, and, hence, the code needs to be written using the underlying termios(3) API. This future code will have enough overlap with the IsTerminal API from golang.org/x/term that it doesn't make sense to use a separate module (ie., golang.org/x/term) for it. #752 #1263
- Loading branch information
1 parent
2149609
commit 34d46db
Showing
8 changed files
with
96 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright © 2023 Red Hat Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package term | ||
|
||
import ( | ||
"os" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func GetState(file *os.File) (*unix.Termios, error) { | ||
fileFD := file.Fd() | ||
fileFDInt := int(fileFD) | ||
state, err := unix.IoctlGetTermios(fileFDInt, unix.TCGETS) | ||
return state, err | ||
} | ||
|
||
func IsTerminal(file *os.File) bool { | ||
if _, err := GetState(file); err != nil { | ||
return false | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright © 2023 Red Hat Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package term | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsTerminalTempFile(t *testing.T) { | ||
dir := t.TempDir() | ||
file, err := os.CreateTemp(dir, "TestIsTerminalTempFile") | ||
assert.NoError(t, err) | ||
fileName := file.Name() | ||
defer os.Remove(fileName) | ||
defer file.Close() | ||
|
||
ok := IsTerminal(file) | ||
assert.False(t, ok) | ||
} | ||
|
||
func TestIsTerminalTerm(t *testing.T) { | ||
file, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0) | ||
assert.NoError(t, err) | ||
defer file.Close() | ||
|
||
ok := IsTerminal(file) | ||
assert.True(t, ok) | ||
} |