aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-12 21:00:26 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-12 21:00:26 +0100
commitd751f65b6dc8bfc389856a61366bff66874dd7d3 (patch)
treec3449668c6b2777291455b5951fd95cbb65d71a7 /src
parent2909766056d5c8663f228205f902f3c77cbc6eeb (diff)
downloadchawan-d751f65b6dc8bfc389856a61366bff66874dd7d3.tar.gz
buffersource: remove location field
Diffstat (limited to 'src')
-rw-r--r--src/local/container.nim21
-rw-r--r--src/local/pager.nim36
-rw-r--r--src/server/buffer.nim5
-rw-r--r--src/types/buffersource.nim2
4 files changed, 33 insertions, 31 deletions
diff --git a/src/local/container.nim b/src/local/container.nim
index 9af35c63..a66104f4 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -139,7 +139,7 @@ proc newBuffer*(forkserver: ForkServer, config: BufferConfig,
let attrs = getWindowAttributes(stdout)
let (process, loaderPid) = forkserver.forkBuffer(source, config, attrs)
if fd != -1:
- loaderPid.passFd(source.location.host, fd)
+ loaderPid.passFd(source.request.url.host, fd)
if fd == 0:
# We are passing stdin.
closeStdin()
@@ -184,7 +184,7 @@ proc newBufferFrom*(forkserver: ForkServer, attrs: WindowAttributes,
)
func location*(container: Container): URL {.jsfget.} =
- return container.source.location
+ return container.source.request.url
proc clone*(container: Container, newurl: URL): Promise[Container] =
let url = if newurl != nil:
@@ -226,7 +226,7 @@ proc clone*(container: Container, newurl: URL): Promise[Container] =
cloned: true
)
if newurl != nil:
- ncontainer.source.location = newurl
+ ncontainer.source.request.url = newurl
return ncontainer
)
@@ -344,15 +344,17 @@ func maxScreenWidth(container: Container): int =
func getTitle*(container: Container): string {.jsfunc.} =
if container.title != "":
return container.title
- return container.source.location.serialize(excludepassword = true)
+ return container.location.serialize(excludepassword = true)
func currentLineWidth(container: Container): int =
if container.numLines == 0: return 0
return container.currentLine.width()
-func maxfromy(container: Container): int = max(container.numLines - container.height, 0)
+func maxfromy(container: Container): int =
+ return max(container.numLines - container.height, 0)
-func maxfromx(container: Container): int = max(container.maxScreenWidth() - container.width, 0)
+func maxfromx(container: Container): int =
+ return max(container.maxScreenWidth() - container.width, 0)
func atPercentOf*(container: Container): int =
if container.numLines == 0: return 100
@@ -1355,7 +1357,7 @@ proc onload*(container: Container, res: LoadResult) =
container.setNumLines(lines, true)
container.needslines = true
container.triggerEvent(LOADED)
- if not container.hasstart and container.source.location.anchor != "":
+ if not container.hasstart and container.location.anchor != "":
return container.iface.gotoAnchor()
).then(proc(res: Opt[tuple[x, y: int]]) =
if res.isSome:
@@ -1377,7 +1379,8 @@ proc load(container: Container) =
# set referrer policy, if any
if res.referrerpolicy.isSome and container.config.referer_from:
container.config.referrerpolicy = res.referrerpolicy.get
- container.setLoadInfo("Connected to " & $container.source.location & ". Downloading...")
+ container.setLoadInfo("Connected to " & $container.location &
+ ". Downloading...")
if res.needsAuth:
container.triggerEvent(NEEDS_AUTH)
if res.redirect != nil:
@@ -1510,7 +1513,7 @@ proc windowChange*(container: Container, attrs: WindowAttributes) =
container.needslines = true)
proc peek(container: Container) {.jsfunc.} =
- container.alert($container.source.location)
+ container.alert($container.location)
proc clearHover*(container: Container) =
container.lastpeek = low(HoverType)
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 41ecb6a5..50591ee3 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -679,7 +679,7 @@ proc gotoURL(pager: Pager, request: Request, prevurl = none(URL),
ctype = none(string), cs = CHARSET_UNKNOWN, replace: Container = nil,
redirectdepth = 0, referrer: Container = nil) =
if referrer != nil and referrer.config.referer_from:
- request.referer = referrer.source.location
+ request.referer = referrer.location
var bufferconfig = pager.applySiteconf(request.url)
if prevurl.isNone or not prevurl.get.equals(request.url, true) or
request.url.hash == "" or request.httpMethod != HTTP_GET:
@@ -692,8 +692,7 @@ proc gotoURL(pager: Pager, request: Request, prevurl = none(URL),
let source = BufferSource(
request: request,
contentType: ctype,
- charset: cs,
- location: request.url
+ charset: cs
)
if referrer != nil:
bufferconfig.referrerpolicy = referrer.config.referrerpolicy
@@ -733,7 +732,7 @@ proc loadURL*(pager: Pager, url: string, ctype = none(string),
let firstparse = parseURL(url)
if firstparse.isSome:
let prev = if pager.container != nil:
- some(pager.container.source.location)
+ some(pager.container.location)
else:
none(URL)
pager.gotoURL(newRequest(firstparse.get), prev, ctype, cs)
@@ -765,8 +764,7 @@ proc readPipe0*(pager: Pager, ctype: Option[string], cs: Charset,
let source = BufferSource(
request: newRequest(location),
contentType: some(ctype.get("text/plain")),
- charset: cs,
- location: location
+ charset: cs
)
return pager.newBuffer(bufferconfig, source, title = title,
canreinterpret = canreinterpret, fd = fd)
@@ -836,12 +834,12 @@ proc updateReadLine*(pager: Pager) =
pager.username = lineedit.news
pager.setLineEdit("Password: ", PASSWORD, hide = true)
of PASSWORD:
- let url = newURL(pager.container.source.location)
+ let url = newURL(pager.container.location)
url.username = pager.username
url.password = lineedit.news
pager.username = ""
pager.gotoURL(
- newRequest(url), some(pager.container.source.location),
+ newRequest(url), some(pager.container.location),
replace = pager.container,
referrer = pager.container
)
@@ -878,12 +876,12 @@ proc load(pager: Pager, s = "") {.jsfunc.} =
else:
var url = s
if url == "":
- url = pager.container.source.location.serialize()
+ url = pager.container.location.serialize()
pager.setLineEdit("URL: ", LOCATION, url)
# Reload the page in a new buffer, then kill the previous buffer.
proc reload(pager: Pager) {.jsfunc.} =
- pager.gotoURL(newRequest(pager.container.source.location), none(URL),
+ pager.gotoURL(newRequest(pager.container.location), none(URL),
pager.container.contentType, replace = pager.container)
proc setEnvVars(pager: Pager) {.jsfunc.} =
@@ -1186,7 +1184,7 @@ proc handleEvent0(pager: Pager, container: Container, event: ContainerEvent): bo
pager.gotoURL(newRequest(container.retry.pop()),
ctype = container.contentType)
else:
- pager.alert("Can't load " & $container.source.location & " (" &
+ pager.alert("Can't load " & $container.location & " (" &
container.errorMessage & ")")
return false
of SUCCESS:
@@ -1221,7 +1219,7 @@ proc handleEvent0(pager: Pager, container: Container, event: ContainerEvent): bo
of REDIRECT:
if container.redirectdepth < pager.config.network.max_redirect:
pager.alert("Redirecting to " & $event.request.url)
- pager.gotoURL(event.request, some(container.source.location),
+ pager.gotoURL(event.request, some(container.location),
replace = container, redirectdepth = container.redirectdepth + 1,
referrer = pager.container)
else:
@@ -1229,7 +1227,7 @@ proc handleEvent0(pager: Pager, container: Container, event: ContainerEvent): bo
pager.deleteContainer(container)
return false
of ANCHOR:
- var url2 = newURL(container.source.location)
+ var url2 = newURL(container.location)
url2.setHash(event.anchor)
pager.dupeBuffer(container, url2)
of NO_ANCHOR:
@@ -1250,12 +1248,16 @@ proc handleEvent0(pager: Pager, container: Container, event: ContainerEvent): bo
pager.container.readCanceled()
pager.redraw = true
of OPEN:
- if pager.container == nil or not pager.container.isHoverURL(event.request.url):
- pager.ask("Open pop-up? " & $event.request.url).then(proc(x: bool) =
+ let url = event.request.url
+ if pager.container == nil or not pager.container.isHoverURL(url):
+ pager.ask("Open pop-up? " & $url).then(proc(x: bool) =
if x:
- pager.gotoURL(event.request, some(container.source.location), referrer = pager.container))
+ pager.gotoURL(event.request, some(container.location),
+ referrer = pager.container)
+ )
else:
- pager.gotoURL(event.request, some(container.source.location), referrer = pager.container)
+ pager.gotoURL(event.request, some(container.location),
+ referrer = pager.container)
of INVALID_COMMAND: discard
of STATUS:
if pager.container == container:
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 19a1407b..7dcca52f 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -272,7 +272,7 @@ macro task(fun: typed) =
fun
func url(buffer: Buffer): URL =
- return buffer.source.location
+ return buffer.source.request.url
func charsets(buffer: Buffer): seq[Charset] =
if buffer.source.charset != CHARSET_UNKNOWN:
@@ -852,7 +852,6 @@ proc readFromFd*(buffer: Buffer, url: URL, ishtml: bool) {.proxy.} =
let request = newRequest(url)
buffer.source = BufferSource(
request: request,
- location: buffer.source.location,
contentType: some(contentType),
charset: buffer.source.charset
)
@@ -953,7 +952,7 @@ proc clone*(buffer: Buffer, newurl: URL): Pid {.proxy.} =
let ssock = initServerSocket(buffered = false)
buffer.ssock = ssock
ps.write(char(0))
- buffer.source.location = newurl
+ buffer.source.request.url = newurl
for it in buffer.tasks.mitems:
it = 0
let socks = ssock.acceptSocketStream()
diff --git a/src/types/buffersource.nim b/src/types/buffersource.nim
index 675d2a2a..60fd7137 100644
--- a/src/types/buffersource.nim
+++ b/src/types/buffersource.nim
@@ -1,13 +1,11 @@
import std/options
import loader/request
-import types/url
import chakasu/charset
type
BufferSource* = object
- location*: URL
contentType*: Option[string] # override
charset*: Charset # fallback
request*: Request