mirror of
https://github.com/paradoxxxzero/butterfly.git
synced 2026-05-26 07:08:08 +00:00
Add geolocation
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
__version__ = '2.0.0-beta7'
|
||||
__version__ = '2.0.0-beta8'
|
||||
|
||||
|
||||
import os
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
from contextlib import contextmanager
|
||||
from butterfly.utils import ansi_colors as colors
|
||||
import sys
|
||||
import termios
|
||||
import tty
|
||||
|
||||
|
||||
@contextmanager
|
||||
@@ -34,9 +37,33 @@ def text():
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
@contextmanager
|
||||
def sass():
|
||||
sys.stdout.write('\x1bP;SASS|')
|
||||
yield
|
||||
sys.stdout.write('\x1bP')
|
||||
def geolocation():
|
||||
sys.stdout.write('\x1b[?99n')
|
||||
sys.stdout.flush()
|
||||
|
||||
fd = sys.stdin.fileno()
|
||||
old_settings = termios.tcgetattr(fd)
|
||||
try:
|
||||
tty.setraw(sys.stdin.fileno())
|
||||
rv = sys.stdin.read(1)
|
||||
if rv != '\x1b':
|
||||
raise
|
||||
rv = sys.stdin.read(1)
|
||||
if rv != '[':
|
||||
raise
|
||||
rv = sys.stdin.read(1)
|
||||
if rv != '?':
|
||||
raise
|
||||
|
||||
loc = ''
|
||||
while rv != 'R':
|
||||
rv = sys.stdin.read(1)
|
||||
if rv != 'R':
|
||||
loc += rv
|
||||
except:
|
||||
return
|
||||
finally:
|
||||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||
if not loc or ';' not in loc:
|
||||
return
|
||||
return tuple(map(float, loc.split(';')))
|
||||
|
||||
@@ -1167,9 +1167,7 @@
|
||||
}
|
||||
break;
|
||||
case "n":
|
||||
if (!this.prefix) {
|
||||
this.deviceStatus(this.params);
|
||||
}
|
||||
break;
|
||||
case "@":
|
||||
this.insertChars(this.params);
|
||||
@@ -2145,6 +2143,7 @@
|
||||
};
|
||||
|
||||
Terminal.prototype.deviceStatus = function(params) {
|
||||
var ref, ref1;
|
||||
if (!this.prefix) {
|
||||
switch (params[0]) {
|
||||
case 5:
|
||||
@@ -2154,7 +2153,22 @@
|
||||
}
|
||||
} else if (this.prefix === "?") {
|
||||
if (params[0] === 6) {
|
||||
return this.send("\x1b[?" + (this.y + 1) + ";" + (this.x + 1) + "R");
|
||||
this.send("\x1b[?" + (this.y + 1) + ";" + (this.x + 1) + "R");
|
||||
}
|
||||
if (params[0] === 99) {
|
||||
if (((ref = navigator.geolocation) != null ? ref.getCurrentPosition : void 0) == null) {
|
||||
this.send('\x1b[?R');
|
||||
return;
|
||||
}
|
||||
return (ref1 = navigator.geolocation) != null ? ref1.getCurrentPosition((function(_this) {
|
||||
return function(position) {
|
||||
return _this.send("\x1b[?" + position.coords.latitude + ";" + position.coords.longitude + "R");
|
||||
};
|
||||
})(this), (function(_this) {
|
||||
return function(error) {
|
||||
return _this.send('\x1b[?R');
|
||||
};
|
||||
})(this)) : void 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
4
butterfly/static/main.min.js
vendored
4
butterfly/static/main.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -990,7 +990,7 @@ class Terminal
|
||||
|
||||
# CSI Ps n Device Status Report (DSR).
|
||||
when "n"
|
||||
@deviceStatus @params unless @prefix
|
||||
@deviceStatus @params
|
||||
|
||||
# CSI Ps @
|
||||
# Insert Ps (Blank) Character(s) (default = 1) (ICH).
|
||||
@@ -2064,6 +2064,19 @@ class Terminal
|
||||
# cursor position
|
||||
@send "\x1b[?" + (@y + 1) + ";" + (@x + 1) + "R"
|
||||
|
||||
# Custom DSR
|
||||
if params[0] is 99
|
||||
# Geo position
|
||||
unless navigator.geolocation?.getCurrentPosition?
|
||||
@send '\x1b[?R'
|
||||
return
|
||||
navigator.geolocation?.getCurrentPosition (position) =>
|
||||
@send (
|
||||
"\x1b[?" + position.coords.latitude + ";" +
|
||||
position.coords.longitude + "R")
|
||||
, (error) =>
|
||||
@send '\x1b[?R'
|
||||
|
||||
|
||||
## Additions ##
|
||||
|
||||
|
||||
Reference in New Issue
Block a user