~mil/mepo

ref: 041d978478ae78e241802ca9d750677e101c3f5b mepo/scripts/mepo_ui_menu_pin_editor.sh -rwxr-xr-x 2.2 KiB
041d9784Miles Alan Show progress in % complete for transfer datum on tiles while downloading 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env sh
DISPLAYNAME="⊕ Pin editor: Edit, save, and restore pin metadata"
HOTKEY=f
ASYNC=1
# TODO, Sxmo's central menu generates shellpipe statements, for 0.5 syntax
# changes to support async items, pin script needs to be updated to support
# this

mainloop() {
  # E.g. dump pin data to file & wait for complete
  TMPFILE="$(mktemp)"
  printf %b "filedump rp $TMPFILE;"
  while true; do
    cat "$TMPFILE" | grep -q . && break
    sleep 1
  done

  PINDATA="$(cat "$TMPFILE")"

  LAT="$(echo "$PINDATA" | grep 'prefset_n lat' | cut -d ' ' -f3 | tr -d ';')"
  LON="$(echo "$PINDATA" | grep 'prefset_n lon' | cut -d ' ' -f3 | tr -d ';')"
  PINS="$(
    printf %b "$PINDATA" |
    grep '^pin_add' | 
    cut -d ' ' -f6- | 
    tr -d ';]['
  )"

  CHOICE="$(
    printf %b "Close Menu\nAdd Pin\nSave to file\nLoad from file\n$PINS" | 
    PROMPT="Pin editor" mepo_ui_helper_menu.sh
  )"

  if [ "$CHOICE" = "Save to file" ]; then
    FILEPATH="$(
      PROMPT="Filepath" mepo_ui_helper_menu.sh
    )"
    printf %b "filedump p $FILEPATH;"
  elif [ "$CHOICE" = "Load from file" ]; then
    FILEPATH="$(
      PROMPT="Filepath" mepo_ui_helper_menu.sh
    )"
    printf %b "fileload $FILEPATH;"
  elif [ "$CHOICE" = "Add Pin" ]; then
    PIN_TO_ADD="$(
      PROMPT="Pin handle" mepo_ui_helper_menu.sh
    )"
    printf %b "pin_add 0 0 $LAT $LON [$PIN_TO_ADD];"
  elif [ "$CHOICE" = "Close Menu" ]; then
    exit
  elif printf %b "$CHOICE" | grep -q .; then
    PINHANDLE="$CHOICE"
    EDITCHOICE="$(
      printf %b "Delete pin\nUpdate coords\nUpdate handle\nUpdate metadata" | 
      PROMPT="Pin editor ($PINHANDLE)" mepo_ui_helper_menu.sh
    )"
    if [ "$EDITCHOICE" = "Delete pin" ]; then
      printf %b "pin_delete -1 $PINHANDLE;"
    elif [ "$EDITCHOICE" = "Update coords" ]; then
      printf %b # TODO
    elif [ "$EDITCHOICE" = "Update handle" ]; then
      printf %b # TODO
    elif [ "$EDITCHOICE" = "Update metadata" ]; then
      METAKEY="$(PROMPT="($PINHANDLE): Metadata key" mepo_ui_helper_menu.sh)"
      METAVALUE="$(PROMPT="($PINHANDLE): Metadata value" mepo_ui_helper_menu.sh)"
      echo "pin_meta -1 [$PINHANDLE] [$METAKEY] [$METAVALUE];"
    fi
  else
    exit
  fi
}

main() {
  while true; do
    mainloop
  done
}

if [ -n "$1" ]; then "$@"; else main; fi