Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
9a69b210
Commit
9a69b210
authored
Jun 14, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Ui.Ask quits during interrupt
parent
21b6d2a4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
+23
-5
packer/ui.go
packer/ui.go
+23
-5
No files found.
packer/ui.go
View file @
9a69b210
...
@@ -4,6 +4,8 @@ import (
...
@@ -4,6 +4,8 @@ import (
"fmt"
"fmt"
"io"
"io"
"log"
"log"
"os"
"os/signal"
"sync"
"sync"
)
)
...
@@ -101,6 +103,10 @@ func (rw *ReaderWriterUi) Ask(query string) string {
...
@@ -101,6 +103,10 @@ func (rw *ReaderWriterUi) Ask(query string) string {
rw
.
l
.
Lock
()
rw
.
l
.
Lock
()
defer
rw
.
l
.
Unlock
()
defer
rw
.
l
.
Unlock
()
sigCh
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sigCh
,
os
.
Interrupt
)
defer
signal
.
Stop
(
sigCh
)
log
.
Printf
(
"ui: ask: %s"
,
query
)
log
.
Printf
(
"ui: ask: %s"
,
query
)
if
query
!=
""
{
if
query
!=
""
{
if
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
query
+
" "
);
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
query
+
" "
);
err
!=
nil
{
...
@@ -108,12 +114,24 @@ func (rw *ReaderWriterUi) Ask(query string) string {
...
@@ -108,12 +114,24 @@ func (rw *ReaderWriterUi) Ask(query string) string {
}
}
}
}
result
:=
make
(
chan
string
,
1
)
go
func
()
{
var
line
string
var
line
string
if
_
,
err
:=
fmt
.
Fscanln
(
rw
.
Reader
,
&
line
);
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fscanln
(
rw
.
Reader
,
&
line
);
err
!=
nil
{
log
.
Printf
(
"ui: scan err: %s"
,
err
)
log
.
Printf
(
"ui: scan err: %s"
,
err
)
}
}
result
<-
line
}()
select
{
case
line
:=
<-
result
:
return
line
return
line
case
<-
sigCh
:
log
.
Println
(
"Interrupt during Ask call. Returning immediately."
)
fmt
.
Fprintln
(
rw
.
Writer
)
return
""
}
}
}
func
(
rw
*
ReaderWriterUi
)
Say
(
message
string
)
{
func
(
rw
*
ReaderWriterUi
)
Say
(
message
string
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment