Skip to content

Commit

Permalink
Merge branch 'master' into eaf-browser-caret-minor-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
HollowMan6 authored Aug 1, 2020
2 parents 4470e6b + efed03f commit 2a60589
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 59 deletions.
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: EAF Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Ensure you're on the latest master branch, then note the steps to reproduce the behavior.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Versions (please complete the following info):**
- Distro and DE/WM:
- Versions of Dependencies:
- M-x emacs-version:

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: EAF Feature request
about: Suggest an idea for the Emacs Application Framework
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of an alternative solutions or features you've considered, if any.

**Additional context**
Add any other context or screenshots about the feature request here.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ EAF is an extensible framework, one can develop any Qt5 application and integrat
## Install
1. Install EAF dependencies, an explaination of each dependency can be found in [Dependency List](#dependency-list).

The following line is for *Archlinux*, same packages should be available to install on your particular distribution:
The following line is for *Arch*-based distros, same packages should be available to install on your particular distribution:

```Bash
yay -S python-pyqt5 python-pyqt5-sip python-pyqtwebengine python-qrcode python-feedparser python-dbus python-pyinotify python-markdown nodejs aria2 libreoffice python-pymupdf python-grip filebrowser-bin
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ EAF是一个可编程扩展的框架,你可以开发自己的Qt5应用并集
## 安装
1. 安装EAF依赖,对于每个依赖的解释可以在[依赖列表](#依赖列表)找到。

以下这行是针对*Archlinux*,同样的包的安装方式在别的发行版略有不同,请善用搜索引擎:
以下这行是*Arch*系安装方式,同样的包在别的发行版的安装方式略有不同,请善用搜索引擎:

```Bash
yay -S python-pyqt5 python-pyqt5-sip python-pyqtwebengine python-qrcode python-feedparser python-dbus python-pyinotify python-markdown nodejs aria2 libreoffice python-pymupdf python-grip filebrowser-bin
Expand Down
33 changes: 30 additions & 3 deletions app/pdf-viewer/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ def __init__(self, url, config_dir, background_color, buffer_id, emacs_var_dict)
# Init scale and scale mode.
self.scale = 1.0
self.read_mode = "fit_to_width"
# Simple string comparation.
if (self.emacs_var_dict["eaf-pdf-default-zoom"] != "1.0"):
self.read_mode = "fit_to_customize"
self.scale = float(self.emacs_var_dict["eaf-pdf-default-zoom"])
self.horizontal_offset = 0

# Inverted mode.
Expand Down Expand Up @@ -252,8 +256,10 @@ def __init__(self, url, config_dir, background_color, buffer_id, emacs_var_dict)
self.page_annotate_height = 22
self.page_annotate_padding_right = 10
self.page_annotate_padding_bottom = 10
self.page_annotate_light_color = QColor("#333333")
self.page_annotate_dark_color = QColor("#999999")
self.page_annotate_light_color = QColor(self.emacs_var_dict["eaf-emacs-theme-foreground-color"])
self.page_annotate_dark_color = QColor(1-QColor(self.emacs_var_dict["eaf-emacs-theme-foreground-color"]).redF(),\
1-QColor(self.emacs_var_dict["eaf-emacs-theme-foreground-color"]).greenF(),\
1-QColor(self.emacs_var_dict["eaf-emacs-theme-foreground-color"]).blueF())
self.font = QFont()
self.font.setPointSize(12)

Expand All @@ -269,6 +275,16 @@ def __init__(self, url, config_dir, background_color, buffer_id, emacs_var_dict)

self.remember_offset = None

def handle_color(self,color,inverted=False):
r = float(color.redF())
g = float(color.greenF())
b = float(color.blueF())
if inverted:
r = 1.0-r
g = 1.0-g
b = 1.0-b
return (r,g,b)

def repeat_to_length(self, string_to_expand, length):
return (string_to_expand * (int(length/len(string_to_expand))+1))[:length]

Expand Down Expand Up @@ -312,6 +328,10 @@ def get_page_pixmap(self, index, scale):
self.char_dict[index] = self.get_page_char_rect_list(index)
self.select_area_annot_cache_dict[index] = None

if self.emacs_var_dict["eaf-pdf-dark-mode"] == "follow" and os.path.splitext(self.url)[-1] == ".pdf":
col = self.handle_color(QColor(self.emacs_var_dict["eaf-emacs-theme-background-color"]), self.inverted_mode)
page.drawRect(page.rect, color=col, fill=col, overlay=False)

trans = self.page_cache_trans if self.page_cache_trans is not None else fitz.Matrix(scale, scale)
pixmap = page.getPixmap(matrix=trans, alpha=False)

Expand Down Expand Up @@ -859,7 +879,14 @@ def mark_select_char_area(self):
# if only one char selected.
line_rect_list.append(bbox_list[0])

line_rect_list = list(map(lambda x: fitz.Rect(x), line_rect_list))
def check_rect(rect):
tl_x, tl_y, br_x, br_y = rect
if tl_x <= br_x and tl_y <= br_y:
return fitz.Rect(rect)
# discard the illegal rect. return a micro rect
return fitz.Rect(tl_x, tl_y, tl_x+1, tl_y+1)

line_rect_list = list(map(check_rect, line_rect_list))

page = self.document[page_index]
old_annot = self.select_area_annot_cache_dict[page_index]
Expand Down
45 changes: 39 additions & 6 deletions app/terminal/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,32 @@
import threading
import getpass
import json
from urllib import request
from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer

class AppBuffer(BrowserBuffer):
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path):
BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, False)

# Get free port.
self.port = get_free_port()
self.http_url = "http://127.0.0.1:{0}".format(get_free_port())
self.url = url

arguments_dict = json.loads(arguments)
self.command = arguments_dict["command"]
self.start_directory = arguments_dict["directory"]
self.current_directory = self.start_directory
self.index_file = os.path.join(os.path.dirname(__file__), "index.html")
self.executing_command = ""
self.index_file = "{0}/index.html".format(self.http_url)
self.server_js = os.path.join(os.path.dirname(__file__), "server.js")

self.buffer_widget.titleChanged.connect(self.change_title)

http_thread = threading.Thread(target=self.run_http_server, args=())
http_thread.start()

# Start server process.
self.background_process = subprocess.Popen(
"node {0} {1} '{2}' '{3}'".format(self.server_js, self.port, self.start_directory, self.command),
Expand All @@ -67,6 +75,19 @@ def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module
self.timer.start(250)
self.timer.timeout.connect(self.checking_status)

def run_http_server(self):
class Handler(SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
# directory=os.path.dirname(__file__), This argument add in python3.7 after
super().__init__(*args, **kwargs)
def translate_path(self, path):
# On python3.7 before version, http server don't support setting directory
# default use the project path.
path = super().translate_path(path)
return os.path.dirname(__file__) + path[len(os.getcwd()):]
with TCPServer(("127.0.0.1", int(self.http_url.split(":")[-1])), Handler) as h:
h.serve_forever()

def focus_terminal(self):
event = QMouseEvent(QEvent.MouseButtonPress, QPointF(0, 0), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
QApplication.sendEvent(self.buffer_widget.focusProxy(), event)
Expand All @@ -77,16 +98,28 @@ def open_terminal_page(self):
if self.emacs_var_dict["eaf-terminal-dark-mode"] == "true" or \
(self.emacs_var_dict["eaf-terminal-dark-mode"] == "follow" and self.emacs_var_dict["eaf-emacs-theme-mode"] == "dark"):
theme = "dark"
with open(self.index_file, "r") as f:
html = f.read().replace("%1", str(self.port)).replace("%2", "file://" + os.path.join(os.path.dirname(__file__))).replace("%3", theme).replace("%4", self.emacs_var_dict["eaf-terminal-font-size"]).replace("%5", self.current_directory)

with request.urlopen(self.index_file) as f:
html = f.read().decode("utf-8").replace("%1", str(self.port)).replace("%2", self.http_url).replace("%3", theme).replace("%4", self.emacs_var_dict["eaf-terminal-font-size"]).replace("%5", self.current_directory)
self.buffer_widget.setHtml(html)

def checking_status(self):
changed_directory = str(self.buffer_widget.execute_js("title"))
if not changed_directory == self.current_directory:
changed_executing_command = str(self.buffer_widget.execute_js("executing_command"))
if len(changed_executing_command) > 30:
changed_executing_command = changed_executing_command[:30]

if changed_executing_command != self.executing_command and changed_executing_command != "":
self.change_title(changed_executing_command)
self.executing_command = changed_executing_command
elif changed_executing_command == "" and self.executing_command != "" or not changed_directory == self.current_directory:
self.change_title(changed_directory)
self.eval_in_emacs.emit('''(setq default-directory "'''+ changed_directory +'''")''')
self.current_directory = changed_directory
if not changed_directory == self.current_directory:
self.eval_in_emacs.emit('''(setq default-directory "'''+ changed_directory +'''")''')
self.current_directory = changed_directory
if self.executing_command != "":
self.executing_command = ""

if subprocess.Popen.poll(self.background_process) is not None:
self.destroy_buffer()

Expand Down
32 changes: 31 additions & 1 deletion app/terminal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
var socket = new WebSocket("ws://127.0.0.1:%1");
}
catch(err) {
setTimeout('location.reload();',1000);
location.reload();
}
const term = new Terminal({
fontSize: "%4",
Expand All @@ -46,6 +46,7 @@
});

var title = "%5"
var executing_command = ""

const searchAddon = new SearchAddon.SearchAddon();

Expand Down Expand Up @@ -124,13 +125,42 @@

window.addEventListener("resize", sendSizeToServer);

term.onLineFeed(() => {
const buffer = term.buffer;
const new_line = buffer.getLine(buffer.baseY + buffer.cursorY);
if (new_line && !new_line.isWrapped) {
var input_data = get_line_data(buffer, buffer.baseY + buffer.cursorY - 1);
if (input_data.indexOf('$')!=-1){
executing_command = input_data.slice(input_data.indexOf('$')+1).trim()
if(executing_command.startsWith("cd ")) {
executing_command = ""
}
}
}
})
function get_line_data(buffer, line_index) {
let line = buffer.getLine(line_index);
if (!line) {
return;
}
let line_data = line.translateToString(true);
while (line_index > 0 && line.isWrapped) {
line = buffer.getLine(--line_index);
if (!line) {
break;
}
line_data = line.translateToString(false) + line_data;
}
return line_data;
}
}

socket.onmessage = (msg) => {
var re = /:([^\x07].*?)\x07/g;
arr = re.exec(msg.data)
if(arr) {
title = arr[1];
executing_command = ""
}
}

Expand Down
14 changes: 13 additions & 1 deletion core/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ def scroll_to_bottom(self):
''' Scroll to the bottom.'''
self.eval_js("document.scrollingElement.scrollTo({left: 0, top: document.body.scrollHeight, behavior: '" + self.buffer.emacs_var_dict["eaf-browser-scroll-behavior"] + "'})")

@interactive()
def get_selection_text(self):
''' Get the selected text.'''
return self.execute_js(self.get_selection_text_js)
Expand Down Expand Up @@ -426,6 +427,10 @@ def get_link_markers(self):
''' Get link markers.'''
self.eval_js(self.get_markers_raw.replace("%1", self.buffer.emacs_var_dict["eaf-marker-letters"]));

def get_text_markers(self):
''' Get link markers.'''
self.eval_js(self.get_markers_raw.replace("%1", self.buffer.emacs_var_dict["eaf-marker-letters"]).replace("%2", "select_text"));

def get_marker_link(self, marker):
''' Get marker's link.'''
self.goto_marker_js = self.goto_marker_raw.replace("%1", str(marker));
Expand Down Expand Up @@ -892,7 +897,7 @@ def handle_input_message(self, result_tag, result_content):
self._caret_search_text(str(result_content))
elif result_tag == "caret_search_text_backward":
self._caret_search_text(str(result_content), True)
elif result_tag == "jump_link":
elif result_tag == "jump_link" or result_tag == "select_marker_text":
self.buffer_widget.jump_to_link(str(result_content).strip())
elif result_tag == "jump_link_new_buffer":
self.buffer_widget.jump_to_link_new_buffer(str(result_content).strip())
Expand Down Expand Up @@ -928,6 +933,7 @@ def cancel_input_message(self, result_tag):
if result_tag == "jump_link" or \
result_tag == "jump_link_new_buffer" or \
result_tag == "jump_link_background_buffer" or \
result_tag == "select_marker_text" or \
result_tag == "copy_link" or \
result_tag == "edit_url":
self.buffer_widget.cleanup_links()
Expand Down Expand Up @@ -1083,6 +1089,12 @@ def copy_code(self):
self.buffer_widget.get_code_markers()
self.send_input_message("Copy code: ", "copy_code");

@interactive(insert_or_do=True)
def select_text(self):
''' Select Text.'''
self.buffer_widget.get_text_markers()
self.send_input_message("Select Text: ", "select_marker_text");

@interactive(insert_or_do=True)
def open_link(self):
''' Open Link.'''
Expand Down
Loading

0 comments on commit 2a60589

Please sign in to comment.