1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

mac add wiki.menu

This commit is contained in:
shaoying 2018-09-10 18:53:16 +08:00
parent a602e18277
commit ae83873f26
8 changed files with 267 additions and 189 deletions

View File

@ -341,9 +341,16 @@ func (lex *LEX) Close(m *ctx.Message, arg ...string) bool { // {{{
// }}}
var Index = &ctx.Context{Name: "lex", Help: "词法中心",
Caches: map[string]*ctx.Cache{},
Caches: map[string]*ctx.Cache{
"nmat": &ctx.Cache{Name: "nmat", Value: "0", Help: "nmat"},
},
Configs: map[string]*ctx.Config{},
Commands: map[string]*ctx.Command{
"spawn": &ctx.Command{Name: "spawn", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
if _, ok := m.Target().Server.(*LEX); m.Assert(ok) { // {{{
m.Start(fmt.Sprintf("matrix%d", m.Capi("nmat", 1)), "matrix")
} // }}}
}},
"train": &ctx.Command{Name: "train seed [hash [page]", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) { // {{{
page, hash := 1, 1

View File

@ -280,20 +280,20 @@ func (web *WEB) Start(m *ctx.Message, arg ...string) bool { // {{{
web.Configs["logheaders"] = &ctx.Config{Name: "日志输出报文头(yes/no)", Value: "no", Help: "日志输出报文头"}
m.Capi("nserve", 1)
yac := m.Sess("tags", m.Sess("yac").Cmd("scan"))
yac.Cmd("train", "void", "void", "[\t ]+")
yac.Cmd("train", "other", "other", "[^\n]+")
yac.Cmd("train", "key", "key", "[A-Za-z_][A-Za-z_0-9]*")
yac.Cmd("train", "code", "def", "def", "key", "(", "other")
yac.Cmd("train", "code", "def", "class", "key", "other")
yac.Cmd("train", "code", "struct", "struct", "key", "\\{")
yac.Cmd("train", "code", "struct", "\\}", "key", ";")
yac.Cmd("train", "code", "struct", "typedef", "struct", "key", "key", ";")
yac.Cmd("train", "code", "function", "key", "\\*", "key", "(", "other")
yac.Cmd("train", "code", "function", "key", "key", "(", "other")
yac.Cmd("train", "code", "variable", "struct", "key", "key", "other")
yac.Cmd("train", "code", "define", "#define", "key", "other")
// yac := m.Sess("tags", m.Sess("yac").Cmd("scan"))
// yac.Cmd("train", "void", "void", "[\t ]+")
// yac.Cmd("train", "other", "other", "[^\n]+")
// yac.Cmd("train", "key", "key", "[A-Za-z_][A-Za-z_0-9]*")
// yac.Cmd("train", "code", "def", "def", "key", "(", "other")
// yac.Cmd("train", "code", "def", "class", "key", "other")
// yac.Cmd("train", "code", "struct", "struct", "key", "\\{")
// yac.Cmd("train", "code", "struct", "\\}", "key", ";")
// yac.Cmd("train", "code", "struct", "typedef", "struct", "key", "key", ";")
// yac.Cmd("train", "code", "function", "key", "\\*", "key", "(", "other")
// yac.Cmd("train", "code", "function", "key", "key", "(", "other")
// yac.Cmd("train", "code", "variable", "struct", "key", "key", "other")
// yac.Cmd("train", "code", "define", "#define", "key", "other")
//
if m.Cap("protocol") == "https" {
web.Caches["cert"] = &ctx.Cache{Name: "服务证书", Value: m.Conf("cert"), Help: "服务证书"}
web.Caches["key"] = &ctx.Cache{Name: "服务密钥", Value: m.Conf("key"), Help: "服务密钥"}

View File

@ -34,6 +34,7 @@ type YAC struct {
mat []map[byte]*State
state map[State]*State
lex *ctx.Message
*ctx.Context
}

59
usr/library/base.js Normal file
View File

@ -0,0 +1,59 @@
function update(event, module, details, key) {
if (event) {
window[key+"timer"] = !window[key+"timer"];
}
if (!window[key+"timer"]) {
return
}
console.log("update "+key)
setTimeout(function() {
action(event, module, details, key);
update(null, module, details, key);
}, refresh_time);
}
function input(event, module, details, key) {
if (event.code == "Enter") {
action(event, module, details, key);
}
}
function action(event, module, details, key) {
var input = document.getElementsByClassName(key+"_input");
for (var i = 0; i < input.length; i++ ){
if (input[i].value != "") {
details.push(input[i].value)
}
}
ctx.POST("", {module:module, details:details}, function(msg) {
if (msg && msg.result) {
var result = document.getElementsByClassName(key+"_result")[0];
result.innerHTML = msg.result;
}
if (!msg || !msg.append || msg.append.length < 1) {
return
}
var append = document.getElementsByClassName(key+"_append")[0];
if (append.rows.length == msg[msg.append[0]].length+1) {
return
}
append.innerHTML = '';
var tr = append.insertRow(0);
for (var i in msg.append) {
var th = tr.appendChild(document.createElement("th"));
th.appendChild(document.createTextNode(msg.append[i]));
}
for (var i = 0; i < msg[msg.append[0]].length; i++) {
var tr = append.insertRow(1);
for (var j in msg.append) {
var td = tr.appendChild(document.createElement("td"));
td.appendChild(document.createTextNode(msg[msg.append[j]][i]));
}
}
var div = append.parent;
})
return false;
}

154
usr/library/wiki.js Normal file
View File

@ -0,0 +1,154 @@
function jumpto(url) {
if (url == "..") {
var ps = locaiton.href.split();
}
location.href=url;
}
function keyup(event) {
console.log(event);
if (typeof window.control == "function") {
control(event);
}
if (event.key == "z") {
var input = document.getElementsByClassName("query_input")[0];
if (!window.query_show) {
window.query_show = true;
var query = document.getElementsByClassName("query_menu")[0];
var input = query.getElementsByTagName("input")[0];
input.style.visibility = "visible";
input.style.width = "80px";
input.focus();
}
return true
}
return true
}
document.onkeyup = keyup;
function toggle() {
window.list_hide = !window.list_hide;
var list = document.getElementsByClassName("list")[0];
var content = document.getElementsByClassName("content")[0];
if (list_hide) {
list.style.visibility = "hidden";
list.style.width="0px";
list.style.height="0px";
list.style["min-width"]="0px";
content.style.width="100%";
} else {
list.style.visibility = "visible";
list.style.width="15%";
list.style.height="100%";
list.style["min-width"]="180px";
content.style.width="85%";
}
}
function menu() {
var max = 0;
var min = 1000;
var list = [];
var hs = ["h2", "h3"];
for (var i = 0; i < hs.length; i++) {
var head = document.getElementsByTagName(hs[i]);
for (var j = 0; j < head.length; j++) {
head[j].id = "head"+head[j].offsetTop;
list.push({"level": hs[i], "position": head[j].offsetTop, "title": head[j].innerText, "hash": head[j].id})
if (head[j].offsetTop > max) {
max = head[j].offsetTop;
}
if (head[j].offsetTop < min) {
min = head[j].offsetTop;
}
}
}
max = max - min;
for (var i = 0; i < list.length-1; i++) {
for (var j = i+1; j < list.length; j++) {
if (list[j].position < list[i].position) {
var a = list[i];
list[i] = list[j];
list[j] = a;
}
}
}
var index2 = -1;
var index3 = 0;
for (var i = 0; i < list.length; i++) {
if (list[i].level == "h2") {
index2++;
index3=0;
} else {
index3++;
list[i].index3 = index3;
}
list[i].index2 = index2;
}
var m = document.getElementsByClassName("menu");
for (var i = 0; i < m.length; i++) {
for (var j = 0; j < list.length; j++) {
var text = list[j].index2+"."
if (list[j].level == "h3") {
text += list[j].index3
}
text += " "
text += list[j].title;
var h = document.getElementById(list[j].hash)
h.innerText = text
var one = m[i].appendChild(document.createElement("div"));
var a = one.appendChild(document.createElement("a"));
a.href = "#"+list[j].hash;
a.innerText = text+" ("+parseInt((list[j].position-min)/max*100)+"%)";
one.className = list[j].level;
}
}
}
function query(event) {
if (event) {
if (event.code == "Enter") {
jumpto("/wiki/?query="+encodeURIComponent(event.target.value));
}
console.log("what")
return true
}
window.query_show = !window.query_show;
var query = document.getElementsByClassName("query_menu")[0];
var input = query.getElementsByTagName("input")[0];
if (window.query_show) {
input.style.visibility = "visible";
input.style.width = "80px";
} else {
input.style.visibility = "hidden";
input.style.width = "0px";
}
}
var tags_list = {};
ctx.GET("/wiki/define.json", undefined, function(msg){
tags_list = msg["define"];
})
function tags(event) {
console.log(event);
if (event.srcElement.tagName == "CODE") {
var tag = document.getSelection().toString();
console.log(tag);
if (tag && tag.length > 0 && tags_list[tag]) {
var position = tags_list[tag].position;
if (position.length == 1) {
jumpto("/wiki/src/"+position[0].file+"#hash_"+position[0].line);
} else {
jumpto("/wiki/?query="+encodeURIComponent(tag));
}
}
}
}
document.onmouseup = tags;
window.onload = function() {
toggle();
menu();
}

View File

@ -41,66 +41,7 @@
}
</style>
<script src="/library/context.js"></script>
<script>
function update(event, module, details, key) {
if (event) {
window[key+"timer"] = !window[key+"timer"];
}
if (!window[key+"timer"]) {
return
}
console.log("update "+key)
setTimeout(function() {
action(event, module, details, key);
update(null, module, details, key);
}, parseInt({{conf . "refresh_time"}}));
}
function input(event, module, details, key) {
if (event.code == "Enter") {
action(event, module, details, key);
}
}
function action(event, module, details, key) {
var input = document.getElementsByClassName(key+"_input");
for (var i = 0; i < input.length; i++ ){
if (input[i].value != "") {
details.push(input[i].value)
}
}
ctx.POST("", {module:module, details:details}, function(msg) {
if (msg && msg.result) {
var result = document.getElementsByClassName(key+"_result")[0];
result.innerHTML = msg.result;
}
if (!msg || !msg.append || msg.append.length < 1) {
return
}
var append = document.getElementsByClassName(key+"_append")[0];
if (append.rows.length == msg[msg.append[0]].length+1) {
return
}
append.innerHTML = '';
var tr = append.insertRow(0);
for (var i in msg.append) {
var th = tr.appendChild(document.createElement("th"));
th.appendChild(document.createTextNode(msg.append[i]));
}
for (var i = 0; i < msg[msg.append[0]].length; i++) {
var tr = append.insertRow(1);
for (var j in msg.append) {
var td = tr.appendChild(document.createElement("td"));
td.appendChild(document.createTextNode(msg[msg.append[j]][i]));
}
}
var div = append.parent;
})
return false;
}
</script>
<script src="/library/base.js"></script>
</head>
<body>
{{end}}
@ -135,11 +76,10 @@ function action(event, module, details, key) {
</div>
</fieldset>
<script>
var refresh_time = parseInt({{conf . "refresh_time"}});
{{if option . "auto_refresh"}}
update(true, '{{option $msg.Meta "module"}}', ['{{detail $msg.Meta}}'], '{{$key}}');
{{end}}
</script>
{{end}}

View File

@ -5,35 +5,6 @@
{{end}}
{{define "wiki_list"}}
<script>
function jumpto(url) {
if (url == "..") {
var ps = locaiton.href.split();
}
location.href=url;
}
function keyup(event) {
console.log(event);
if (typeof window.control == "function") {
control(event);
}
if (event.key == "z") {
var input = document.getElementsByClassName("query_input")[0];
if (!window.query_show) {
window.query_show = true;
var query = document.getElementsByClassName("query_menu")[0];
var input = query.getElementsByTagName("input")[0];
input.style.visibility = "visible";
input.style.width = "80px";
input.focus();
}
return true
}
return true
}
document.onkeyup = keyup;
</script>
<style>
.container {
height:100%;
@ -120,70 +91,6 @@ document.onkeyup = keyup;
{{end}}
{{define "wiki_body"}}
<script>
function toggle() {
window.list_hide = !window.list_hide;
var list = document.getElementsByClassName("list")[0];
var content = document.getElementsByClassName("content")[0];
if (list_hide) {
list.style.visibility = "hidden";
list.style.width="0px";
list.style.height="0px";
list.style["min-width"]="0px";
content.style.width="100%";
} else {
list.style.visibility = "visible";
list.style.width="15%";
list.style.height="100%";
list.style["min-width"]="180px";
content.style.width="85%";
}
}
function query(event) {
if (event) {
if (event.code == "Enter") {
jumpto("/wiki/?query="+encodeURIComponent(event.target.value));
}
console.log("what")
return true
}
window.query_show = !window.query_show;
var query = document.getElementsByClassName("query_menu")[0];
var input = query.getElementsByTagName("input")[0];
if (window.query_show) {
input.style.visibility = "visible";
input.style.width = "80px";
} else {
input.style.visibility = "hidden";
input.style.width = "0px";
}
}
var tags_list = {};
ctx.GET("/wiki/define.json", undefined, function(msg){
tags_list = msg["define"];
})
function tags(event) {
console.log(event);
if (event.srcElement.tagName == "CODE") {
var tag = document.getSelection().toString();
console.log(tag);
if (tag && tag.length > 0 && tags_list[tag]) {
var position = tags_list[tag].position;
if (position.length == 1) {
jumpto("/wiki/src/"+position[0].file+"#hash_"+position[0].line);
} else {
jumpto("/wiki/?query="+encodeURIComponent(tag));
}
}
}
}
document.onmouseup = tags;
window.onload = function() {
toggle();
}
</script>
<style>
.content {
width:85%;
@ -218,17 +125,26 @@ window.onload = function() {
height:16px;
}
.record {
margin: 10px 40px;
/* float:right; */
margin: 10px 10px;
float:left;
}
.menu {
}
.menu a {
text-decoration:none;
}
.menu .h3 {
padding-left: 10px;
}
</style>
<div class="content">
<div class="toggle" title="点击,显示或隐藏目录" onclick="toggle()"></div>
{{if option . "modify_time"|meta}}
<div class="record">上次修订时间: {{option . "modify_time"|meta}} 修订次数: {{option . "modify_count"|meta}}</div>
{{end}}
<div class="record">上次阅读时间: {{option . "last_record_time"|meta}} 总访问量: {{option . "record_count"|meta}}</div>
{{if option . "modify_time"|meta}}
<div class="record">上次修订时间: {{option . "modify_time"|meta}} 修订次数: {{option . "modify_count"|meta}}</div>
{{end}}
<div class="record">上次阅读时间: {{option . "last_record_time"|meta}} 总访问量: {{option . "record_count"|meta}}</div>
<div class="texts">
<div class="menu"></div>
<div class="number">
{{range option . "nline"|meta|list}}
<div id="hash_{{.}}" style="margin-top:-1px"><code>{{.}}</code></div>
@ -254,12 +170,13 @@ window.onload = function() {
<ul>
{{end}}
{{else if append . "code"|meta}}
<p><pre><code>{{append . "code"|meta}}</code></pre><p>
{{else}}
<p>{{append . "body"|meta|unscaped}}</p>
<p><pre><code>{{append . "code"|meta}}</code></pre><p>
{{else}}
<p>{{append . "body"|meta|unscaped}}</p>
{{end}}
</div>
</div>
</div>
<script src="/library/wiki.js"></script>
{{end}}

View File

@ -1,4 +1,4 @@
## 0. 简介
## 简介
zsh 和bash一样是一种终端的shell但提供了更丰富的功能更快捷的补全。
@ -12,7 +12,7 @@ vim 是一款强大的编辑器,通过模式化快捷键提升编辑速度,
- Mac包管理器: <https://brew.sh/>
### 0.1 zsh安装
### zsh安装
Mac上自带zsh不用安装但Ubuntu上需要自己安装一下。
```
$ sudo apt-get install zsh
@ -25,7 +25,7 @@ $ chsh -s /usr/bin/zsh
```
$ curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
```
### 0.2 tmux安装
### tmux安装
Ubuntu上安装
```
$ sudo apt-get install tmux
@ -42,7 +42,7 @@ $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/maste
```
$ tmux
```
### 0.3 vim安装
### vim安装
Mac上自带vim不需要安装但Ubuntu需要自己安装一下。
```
$ sudo apt-get install vim
@ -51,12 +51,12 @@ vim有很丰富的插件可以下载一个插件管理器。
```
$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
```
## 1. 基本快捷键
### 1.1 zsh使用
### 1.2 tmux使用
### 1.3 vim使用
## 2. 个性化配置
## 3. 源码解析
## 基本快捷键
### zsh使用
### tmux使用
### vim使用
## 个性化配置
## 源码解析
Mac上安装pip
```
$ sudo easy_install pip