-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #467 from Unpackerr/unstable
Fix history bug
- Loading branch information
Showing
4 changed files
with
48 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package unpackerr | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/Unpackerr/unpackerr/pkg/ui" | ||
) | ||
|
||
// Safety constants. | ||
const ( | ||
hist = "hist_" | ||
histNone = "hist_none" | ||
) | ||
|
||
// History holds the history of extracted items. | ||
type History struct { | ||
Items []string | ||
Finished uint | ||
Retries uint | ||
Map map[string]*Extract | ||
} | ||
|
||
// This is called every time an item is queued. | ||
func (u *Unpackerr) updateHistory(item string) { | ||
if u.KeepHistory == 0 { | ||
return | ||
} | ||
|
||
if ui.HasGUI() && item != "" { | ||
u.menu[histNone].Hide() | ||
} | ||
|
||
u.History.Items[0] = item | ||
|
||
// Do not process 0; this isn't an `intrange`. | ||
for idx := len(u.History.Items) - 1; idx > 0; idx-- { | ||
// u.History.Items is a slice with a set (identical) length and capacity. | ||
switch u.History.Items[idx] = u.History.Items[idx-1]; { | ||
case !ui.HasGUI(): | ||
continue | ||
case u.History.Items[idx] != "": | ||
u.menu[hist+strconv.Itoa(idx)].SetTitle(u.History.Items[idx]) | ||
u.menu[hist+strconv.Itoa(idx)].Show() | ||
default: | ||
u.menu[hist+strconv.Itoa(idx)].Hide() | ||
} | ||
} | ||
} |
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