code-server icon indicating copy to clipboard operation
code-server copied to clipboard

Allow custom fonts

Open gjrtimmer opened this issue 4 years ago • 90 comments

Feature Request

I would like the ability to have the ability to have the font I use for all my development FireCode to be included so its pushed to the client.

I'm not really a star when it comes to CSS, but maybe this would be possible with something like a @font-face which would push the font to the client. Then when you configure the font in Code, because its pushed to the client you can have the FireCode font and ligatures without installing the font on the client.

I would also accept solutions from anyone, how to hack some files to get this working.

Hopefully I'm not the only one using this font.

With Kind Regards, Gert-Jan Timmer

gjrtimmer avatar Feb 27 '20 09:02 gjrtimmer

You can do this with a Cloudflare app in front of your sub domain for code. Works pretty well. Was not able to find a way to do it via reverse proxy/etc.

Just-Insane avatar Feb 27 '20 21:02 Just-Insane

I would agree it should be a first class feature as fonts are a big part of editor customization and development.

nhooyr avatar Feb 27 '20 21:02 nhooyr

Will make this a priority. Agreed it's a big one.

kylecarbs avatar Feb 27 '20 22:02 kylecarbs

Thank you, it would really help at lot of people.

gjrtimmer avatar Mar 05 '20 20:03 gjrtimmer

This would be an amazing feature so I can finally include a powerline font that would go great with Oh My Zsh.

demyxco avatar Mar 05 '20 20:03 demyxco

@Just-Insane you say this is possible with cloudflare? where and how?

Merith-TK avatar Mar 10 '20 19:03 Merith-TK

Under the Apps section for your domain in Cloudflare, you should find an app called "Add CSS" developed by Cloudflare Labs.

In the settings for this app, you select your subdomain that code-server is running on, and then enter the CSS:

@font-face {
  font-family: 'Fira Code';
  src: url('https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/woff2/FiraCode-Light.woff2') format('woff2'),
    url("https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/woff/FiraCode-Light.woff") format("woff");
  font-weight: 300;
  font-style: normal;
}

@font-face {
  font-family: 'Fira Code';
  src: url('https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/woff2/FiraCode-Regular.woff2') format('woff2'),
    url("https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/woff/FiraCode-Regular.woff") format("woff");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: 'Fira Code';
  src: url('https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/woff2/FiraCode-Medium.woff2') format('woff2'),
    url("https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/woff/FiraCode-Medium.woff") format("woff");
  font-weight: 500;
  font-style: normal;
}

@font-face {
  font-family: 'Fira Code';
  src: url('https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/woff2/FiraCode-Bold.woff2') format('woff2'),
    url("https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/woff/FiraCode-Bold.woff") format("woff");
  font-weight: 700;
  font-style: normal;
}

@font-face {
  font-family: 'Fira Code VF';
  src: url('https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/woff2/FiraCode-VF.woff2') format('woff2-variations'),
       url('https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/woff/FiraCode-VF.woff') format('woff-variations');
  /* font-weight requires a range: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide#Using_a_variable_font_font-face_changes */
  font-weight: 300 700;
  font-style: normal;
}

I don't exactly remember where I found this from (CDN URL in the CSS), but the overall CSS file is available on github: https://github.com/tonsky/FiraCode/blob/master/distr/fira_code.css

Just-Insane avatar Mar 10 '20 19:03 Just-Insane

neat, is it possible to make this an extension? to load a font off the internet?

Merith-TK avatar Mar 10 '20 20:03 Merith-TK

@Just-Insane very cool. Great workaround for now!

kylecarbs avatar Mar 10 '20 21:03 kylecarbs

There is probably a way you can intercept the pages using nginx/Apache as a reverse proxy, but I wasn’t able to get it working in the time I had.

Just-Insane avatar Mar 10 '20 22:03 Just-Insane

@Just-Insane does this enable font ligatures? like converting => to the special char?

Merith-TK avatar Mar 13 '20 16:03 Merith-TK

That is correct, it does the same as if you installed Fira Code for VS Code on your desktop.

On Mar 13, 2020, at 12:09 PM, Merith [email protected] wrote:



@Just-Insanehttps://github.com/Just-Insane does this enable font ligatures? like converting => to the special char?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/cdr/code-server/issues/1374#issuecomment-598798988, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADZKZDFECEUIBM7UKS62T53RHJLE5ANCNFSM4K4XF2LQ.

Just-Insane avatar Mar 13 '20 16:03 Just-Insane

For me using FiraCode just works.

I am using macOS and I've added FiraCode to the OS. Probably if you register the font with other OSes it will work as well.

gyzerok avatar May 13 '20 08:05 gyzerok

Might have been added to vscode-web.

cc @code-asher

nhooyr avatar May 13 '20 08:05 nhooyr

Installing the font should always work but I think this feature request is for using a webfont which I don't believe is supported yet.

code-asher avatar May 13 '20 15:05 code-asher

Installing the font should always work but I think this feature request is for using a webfont which I don't believe is supported yet.

Yes, this is for the web server telling the client to use a specific font (usually CSS). Installing a font on the OS of each system you may want to use is not always possible.

Just-Insane avatar May 13 '20 15:05 Just-Insane

well installing the font assumes you are on a computer where you are able to do so.

Windows: requires admin+reboot to properly install font, and even then custom fonts may be disabled by an admin at a workplace Linux: Requires that your computer actually knows how to handle the font (most systems are, but there is that one chance) MacOS: No clue on this one, never used a mac for this sortof stuff Chromebook: Name one way to install a font on a chromebook that is official from google and not a JS or CSS injection.

EDIT: just realized this ties in with

Yes, this is for the web server telling the client to use a specific font (usually CSS). Installing a font on the OS of each system you may want to use is not always possible.

Merith-TK avatar May 13 '20 17:05 Merith-TK

MacOS: No clue on this one, never used a mac for this sortof stuff

Installing fonts on macOS requires users to open the font file they want to install then click the Install Font button in the new window. The font is now available system wide.

The ability to load any font (without it installed on the user’s machine) would make it possible to bundle the font(s) directly into a package. Example would be a Docker image; all my code-server containers are in remote machines.

demyxco avatar May 13 '20 19:05 demyxco

honestly, making it so it loads custom font files from $DATA_DIR/fonts via some js in the actual code would work

Merith-TK avatar May 13 '20 21:05 Merith-TK

What I noticed on MacOS and iPadOS is that even if you install custom fonts, Safari doesn't use them. Though somehow Firefox manages to display them. So it's an issue with Safari as far as I can tell. To overcome this, it would be nice if we could inject @font-face{url(/font/dir/font)} etc. without client-side code injection extensions. (Extensions are not allowed on ipadOS.)

canbakiskan avatar May 27 '20 23:05 canbakiskan

@canbakiskan what could be done would be a simple addition to the code where it reads fonts and loads them in the CSS

Merith-TK avatar May 28 '20 00:05 Merith-TK

@canbakiskan wrote:

What I noticed on MacOS and iPadOS is that even if you install custom fonts, Safari doesn't use them. Though somehow Firefox manages to display them. So it's an issue with Safari as far as I can tell. To overcome this, it would be nice if we could inject @font-face{url(/font/dir/font)} etc. without client-side code injection extensions. (Extensions are not allowed on ipadOS.)

I’m having the same issue. I’ve tried to use the SourceCodePro+Powerline+Awesome+Regular.ttf fonts in iPad without success. I installed custom fonts in iPad but seems the Safari, Firefox and Chrome don’t recognize the custom font even if "terminal.integrated.fontFamily": "SourceCodePro+Powerline+Awesome" has been configured in code-server’ settings.json.

Yes, it would be nice if we could inject @font-face{url(/font/dir/font)} and package the custom fonts in the code-server.

Regards.

chilcano avatar Jun 04 '20 21:06 chilcano

For those of you who are still looking for a solution I've managed to solve this by using NGINX as a reverse proxy to serve the downloaded fonts from a custom directory injecting a custom css file.

Now I'm able to use VS Code on my iPad Pro with the programming ligatures enabled.

Here's my nginx config:

server {
    listen 8081;

    location / {
        proxy_pass http://localhost:8080;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        sub_filter
        '</head>'
        '<link rel="stylesheet" type="text/css" href="/ios-fonts/css/fonts.css">
        </head>';
        sub_filter_once on;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;
    }

    location /ios-fonts {
        autoindex on;
        root /var/www/html;
    }
}

And then I have inside /var/www/html this structure:

.
└── ios-fonts
    ├── css
    │   └── fonts.css
    └── fonts
        ├── FiraCode-Regular.woff
        └── FiraCode-Regular.woff2

And this is the content of fonts.css

@font-face {
  font-family: 'Fira Code';
  src: url('/ios-fonts/fonts/FiraCode-Regular.woff2') format('woff2'),
    url("/ios-fonts/fonts/FiraCode-Regular.woff") format("woff");
  font-weight: 400;
  font-style: normal;
}

The reason I don't have any references to my domain or certificates on the nginx config is because I manage all my certificates using Traefik, so here's what I do:

[http.routers]
  [http.routers.code-server]
      entryPoints = ["https"]
      rule = "Host(`vscode.mydomain.com`)"
      service = "code-server"
      middlewares = ["secureheaders"]
      [http.routers.code-server.tls]
        certresolver = "letsencrypt"

[http.services]
  [http.services.code-server]
    [http.services.code-server.loadBalancer]
      [[http.services.code-server.loadBalancer.servers]]
        url = "http://ip-of-code-server:8081"

So yeah, although not ideal, kinda hacky and double proxied, that's the only solution I could find for now.

mateusrevoredo avatar Jun 12 '20 11:06 mateusrevoredo

Thanks @mateusrevoredo !! That's amazing.

chilcano avatar Jun 12 '20 11:06 chilcano

My solution is inserting css directly to lib/vscode/out/vs/workbench/workbench.web.api.css to use my font in editor and powerline font in terminal. The only problem is you have to run patch again after you upgrading code-server. I created a shell script to do that, check it out, you can modify it to use your favorite fonts https://github.com/tuanpham-dev/code-server-font-patch

tuanpham-dev avatar Jun 19 '20 20:06 tuanpham-dev

I have created a Pacman Hook that automatically insert Fira Code Font to website for Arch Linux users using method from tuanpham-dev's comment.

moelife-coder avatar Jun 26 '20 09:06 moelife-coder

Below method will help you to load any font in vscode, I am loading Fira Code from Google fonts by loading in Nginx conf

       location / {
            proxy_pass http://127.0.0.1:8080/;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection upgrade;
            proxy_set_header Accept-Encoding gzip;
            proxy_set_header Host $host;
            sub_filter '</head>' '<link type="text/css" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;400;500;600;700&display=swap" rel="stylesheet"></head>';
            sub_filter 'font-src' 'font-src fonts.gstatic.com';
            sub_filter 'style-src' 'style-src fonts.googleapis.com';
            sub_filter_once on;
        }

and than loading in my settings file

{
    "editor.fontSize": 16,
    "editor.fontFamily": "Fira Code",
    "editor.fontLigatures": true,
    "editor.fontWeight": "500"
}

If you wants to add manually you can modify lib/code-server-3.6.0/src/browser/pages/vscode.html but keep note, it will break if you update vscode

add fonts before </head> <link type="text/css" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;400;500;600;700&display=swap" rel="stylesheet">

and update Content-Security-Policy to allow loading those fonts

<meta
      http-equiv="Content-Security-Policy"
      content="font-src 'self' fonts.gstatic.com data:; connect-src ws: wss: 'self' https:; default-src ws: wss: 'self'; 
style-src 'self' 'unsafe-inline' fonts.googleapis.com; script-src 'self' 'unsafe-inline' 'unsafe-eval'; 
manifest-src 'self'; img-src 'self' data: https:;"
    />

RazaGR avatar Oct 18 '20 23:10 RazaGR

Thanks everyone for the inputs. I was able to add custom fonts to my ingress controller using nginx conf.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/server-snippet: |-
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
      proxy_set_header Host $host;
      sub_filter '</head>' '<link type="text/css" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;400;500;600;700&display=swap" rel="stylesheet"></head>';
      sub_filter 'font-src' 'font-src fonts.gstatic.com';
      sub_filter 'style-src' 'style-src fonts.googleapis.com';
      sub_filter_once on;
...

Helm chart is here if anyone wants to see: https://github.com/sqylabs/charts/tree/master/charts/code-server

ghokun avatar Oct 20 '20 08:10 ghokun

These dont solve the actual issue of having the fonts loaded. there are instances where people may be running code-server, on LAN and NOT behind a webserver like nginx or what you guys may use.

The original question appeared to want to load fonts from code-server itself. not having HTML injected by a webserver,

Merith-TK avatar Oct 20 '20 18:10 Merith-TK

@Merith-TK Correct, I want to be able to configure this within the code-server itself

gjrtimmer avatar Oct 22 '20 13:10 gjrtimmer

sudo sed -i 's/<\/head>/<link type="text\/css" href="https:\/\/fonts.googleapis.com\/css2?family=Fira+Code:wght@300;400;500;600;700\&display=swap" rel="stylesheet"><\/head>/g' /usr/lib/code-server/src/browser/pages/vscode.html
sudo sed -i 's/font-src/font-src fonts.gstatic.com/g' /usr/lib/code-server/src/browser/pages/vscode.html
sudo sed -i 's/style-src/style-src fonts.googleapis.com/g' /usr/lib/code-server/src/browser/pages/vscode.html

just make it as a shell script and run you can use Fira Code Font without install And also after an update you don't need to edit again. just run this script!! very simple!!!

whtjs avatar Oct 24 '20 21:10 whtjs

okay. wouldnt it be more sane to write an extension for this? like execute JS to load CSS automatically?

Merith-TK avatar Oct 24 '20 23:10 Merith-TK

@whtjs your solution is the cleanest and fastest way to import a font without using nginx or any other weird hacks. Thank you! Now I can automate installation of oh-my-zsh with a powerlevel10k theme.

Screen Shot 2021-01-21 at 12 10 58 AM

demyxco avatar Jan 21 '21 07:01 demyxco

If you use apache can use mod_substitute

` AddOutputFilterByType SUBSTITUTE text/html

Substitute "s|||i"

Substitute "s|font-src|font-src fonts.gstatic.com|"

Substitute "s|style-src|style-src fonts.googleapis.com|"`

dgironella avatar Feb 02 '21 11:02 dgironella

The main problem is that of these are workarounds rather than addressing the actual concern.

The config inside of the settings.json could be

codeserver.FontLoader:{ "font name" : "path to font on host", "second font" : "path to font on host" }

On Tue, Feb 2, 2021, 3:10 AM David Gironella Casademont < [email protected]> wrote:

If you use apache can use mod_substitute

AddOutputFilterByType SUBSTITUTE text/html Substitute "s|||i" Substitute "s|font-src|font-src fonts.gstatic.com|" Substitute "s|style-src|style-src fonts.googleapis.com |"

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cdr/code-server/issues/1374#issuecomment-771560299, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPQOXVPREU7SABMQJSO7UDS47MTLANCNFSM4K4XF2LQ .

Merith-TK avatar Feb 02 '21 15:02 Merith-TK

What is the State right now? I want to use Fira Code... Do I have to use the Cloudflare hack?

Edit: Works using Cloudflare App, but would be cool as a Feature

kaaax0815 avatar Feb 22 '21 16:02 kaaax0815

What is the State right now? I want to use Fira Code... Do I have to use the Cloudflare hack?

Edit: Works using Cloudflare App, but would be cool as a Feature

You have to use the cloudflare hack, no way around it as far as i know.

Merith-TK avatar Feb 22 '21 18:02 Merith-TK

What is the State right now? I want to use Fira Code... Do I have to use the Cloudflare hack?

Edit: Works using Cloudflare App, but would be cool as a Feature

You can use cloudflare hack, or mod_substitute on apache as I show above

dgironella avatar Feb 23 '21 08:02 dgironella

Using sed to edit /usr/lib/code-server/src/browser/pages/vscode.html works for me but the fonts are hosted on my site and on a different domain.

demyxco avatar Feb 23 '21 16:02 demyxco

@demyxco What did you change?

kaaax0815 avatar Feb 23 '21 16:02 kaaax0815

@kaaax0815 see my repo https://github.com/demyxco/code-server/blob/master/tag-latest/Dockerfile#L113-L124

Can confirm on my iPad that it works; it doesn't have the MesloLGS NF fonts installed locally.

IMG_0349

demyxco avatar Feb 23 '21 16:02 demyxco

But that also assumes that the user is using code-server in docker. which does not match 100% usecases

also what is that theme? looks sick

Merith-TK avatar Feb 23 '21 19:02 Merith-TK

@Merith-TK I don't have experience in using code-server outside of Docker but I'm assuming you can just edit that same file and it'll load it anyways?

The theme is called Material Theme.

demyxco avatar Feb 23 '21 22:02 demyxco

I'm assuming you can just edit that same file and it'll load it anyways?

Yes thats true. But I think a proper feature would be better, then like a hacky tutorial, Its in Triage, so it does get looked on in the feature, but a reference in the docs would be good until a proper release

kaaax0815 avatar Feb 23 '21 22:02 kaaax0815

We want an OFFICIAL method, not a jank method —Merith

On Tue, Feb 23, 2021 at 2:17 PM kaaaxcreators [email protected] wrote:

I'm assuming you can just edit that same file and it'll load it anyways?

Yes thats true. But I think a proper feature would be better, then like a hacky tutorial, Its in Triage, so it does get looked on in the feature, but a reference in the docs would be good until a proper release

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cdr/code-server/issues/1374#issuecomment-784552990, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPQOXQ5CXXF35JGVU2GRKTTAQSQVANCNFSM4K4XF2LQ .

Merith-TK avatar Feb 24 '21 00:02 Merith-TK

sudo sed -i 's/<\/head>/<link type="text\/css" href="https:\/\/fonts.googleapis.com\/css2?family=Fira+Code:wght@300;400;500;600;700\&display=swap" rel="stylesheet"><\/head>/g' /usr/lib/code-server/src/browser/pages/vscode.html
sudo sed -i 's/font-src/font-src fonts.gstatic.com/g' /usr/lib/code-server/src/browser/pages/vscode.html
sudo sed -i 's/style-src/style-src fonts.googleapis.com/g' /usr/lib/code-server/src/browser/pages/vscode.html

just make it as a shell script and run you can use Fira Code Font without install And also after an update you don't need to edit again. just run this script!! very simple!!!

@whtjs You're an absolute legend. I was pulling my hair out. Thanks.

baufometic avatar Mar 26 '21 12:03 baufometic

hterm handles this by bundling a few popular fonts, and then allowing custom CSS to inject web fonts.

https://chromium.googlesource.com/apps/libapps/+/master/nassh/doc/FAQ.md#how-do-i-change-the-font-face

Since on Chrome OS there is no way to install system-wide fonts, I believe this is a matter of VS Code feature parity.

FiloSottile avatar Oct 25 '21 17:10 FiloSottile

I mean theoretically It should not be that hard to add a setting to code-server that is just a list of fonts and their locations, somewhat like this?

{ "codeserver.fonts": [
  {
    "name": "Font Name",
    "type": "url",
    "source": "https://example.com/font.file"
  },
  {
    "name": "Font Name",
    "type": "file",
    "source": "/home/coder/.fonts/font.file" // Must be accessible by Code-Server 
  },
]}

For url it would just load that as an external resource using its own CSS for file it would copy the font file to a tempdir and serve that alongside its own CSS

Merith-TK avatar Oct 26 '21 01:10 Merith-TK

Accepting a list of webfonts to load via CSS makes sense as a solution here, it doesn't require anything specific on the computer you load the code-server URL in. 👍

It would be more flexible to accept either CSS snippets or CSS URLs (or both). The hterm document includes this example:

@import url('https://fonts.googleapis.com/css?family=Roboto+Mono');

If you load that URL you'll see that there are two different woff2 files referenced depending on the glyphs. So if you type a non-Latin letter, an additional woff2 would be downloaded to display it. Fira Code is the same: https://fonts.googleapis.com/css2?family=Fira+Code I wouldn't want to reinvent this glyph stuff inside some code-server-specific config format 😅

danopia avatar Oct 26 '21 09:10 danopia

Version 4.x broke the custom font hack since code-server/src/browser/pages/vscode.html doesn't exist anymore 😔

Also a header setting is preventing external fonts from loading:

Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'".

demyxco avatar Jan 15 '22 02:01 demyxco

@demyxco There is <install-path>/vendor/modules/code-oss-dev/out/vs/code/browser/workbench/workbench.html now.

benz0li avatar Jan 15 '22 07:01 benz0li

@benz0li awesome, can confirm it works on my iPad, which has no other fonts installed.

demyxco avatar Jan 15 '22 20:01 demyxco

@demyxco What's your fix for the header error?

Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'".

bjun626 avatar Jan 16 '22 11:01 bjun626

@bjun626 you have to load the fonts locally and not remotely https://github.com/demyxco/code-server/blob/master/tag-latest/Dockerfile#L112-L125.

Pretty much place the fonts in the public directory /usr/local/lib/code-server/src/browser/pages and the font-face url would be _static/src/browser/pages/your-custom-font.woff.

demyxco avatar Jan 16 '22 22:01 demyxco

@bjun626 you have to load the fonts locally and not remotely https://github.com/demyxco/code-server/blob/master/tag-latest/Dockerfile#L112-L125.

Pretty much place the fonts in the public directory /usr/local/lib/code-server/src/browser/pages and the font-face url would be _static/src/browser/pages/your-custom-font.woff.

No, you don't. Using CDN to load web fonts would be a much better choice. And here's my approach.

<!-- <install-path>/vendor/modules/code-oss-dev/out/vs/code/browser/workbench/workbench.html -->
<!-- ... -->
<script>
    @import url('https://fonts.googleapis.com/css?family=Fira+Code');
</script>
<!-- ... -->

All I need to do is updating CSP:

cd <install-path> # for me it's /usr/lib/code-server

# update style-src
grep -rl "style-src 'self' 'unsafe-inline'" . | sudo xargs sed -i "s/style-src 'self' 'unsafe-inline'/style-src 'self' 'unsafe-inline' fonts.googleapis.com/g"
# update font-src
grep -rl "font-src 'self' blob:" . | sudo xargs sed -i "s/font-src 'self' blob:/font-src 'self' blob: fonts.gstatic.com/g"

# then restart `code-server`
sudo systemctl restart code-server@$USER

Hope this can help you @bjun626

ManiaciaChao avatar Jan 17 '22 07:01 ManiaciaChao

@ManiaciaChao many ways to go about this 👌 interesting approach though. Since mine is a Docker setup, I'll have to include the fonts during build.

demyxco avatar Jan 17 '22 07:01 demyxco

I've attempted to build off of @moelife-coder's pacman hook for the new folder structure: https://gist.github.com/JettScythe/6d98633d5f98730661127bfe3dbc68a4 But still no luck when using Fira Code as my terminal font family. Any suggestions?

EDIT: Just as a follow up, I removed Fira Code as my font & downloaded the 'MesloLGS NF' font family from https://github.com/romkatv/powerlevel10k#meslo-nerd-font-patched-for-powerlevel10k. Everything appears to be working now!

JettScythe avatar Mar 11 '22 17:03 JettScythe

@ManiaciaChao version 4.2.0, the workbench.html's path is changed: <install-path>/vendor/modules/code-oss-dev/out/vs/code/browser/workbench/workbench.html to <install-path>/lib/vscode/out/vs/code/browser/workbench/workbench.html

However, unless workbench.html's name is changed, this command might always work to load web font(Fira Code Regular). (the path of workbench.html doesn't matter!)

cd /usr/lib/code-server #my install path

#find workbench.html and add style code
find . -name workbench.html | sudo xargs sed -i "s%</head>%<style>@import url('https://fonts.googleapis.com/css2?family=Fira+Code\&display=swap');</style></head>%g"

Therefore, you can apply the font by executing this command.

cd /usr/lib/code-server #my install path

#find workbench.html and add style code
find . -name workbench.html | sudo xargs sed -i "s%</head>%<style>@import url('https://fonts.googleapis.com/css2?family=Fira+Code\&display=swap');</style></head>%g"

# update style-src
grep -rl "style-src 'self' 'unsafe-inline'" . | sudo xargs sed -i "s/style-src 'self' 'unsafe-inline'/style-src 'self' 'unsafe-inline' fonts.googleapis.com/g"
# update font-src
grep -rl "font-src 'self' blob:" . | sudo xargs sed -i "s/font-src 'self' blob:/font-src 'self' blob: fonts.gstatic.com/g"

# then restart code-server

EDIT: workbench.html's path in 4.3.0 is same as 4.2.0!

darkpppet avatar Apr 09 '22 10:04 darkpppet

Can anyone help me with integrating patched Nerd Font on the app? I have tried multiple versions, but it seems that it doesn't work. It doesn't recognize the Nerd Font at all, even through it's installed on the system. I'm running a manjaro system with the server installed locally.

Tobias-Artur avatar May 01 '22 18:05 Tobias-Artur

i have done it!!! i use powerlevel10k on the latest version of code-sever. if you want to change the fonts of code-sever,you must change your fonts on web browser. then you can use oh-my-zsh just like normal( show it below). @gjrtimmer @nhooyr @JettScythe image image

JWleo avatar May 26 '22 08:05 JWleo

@JWleo me too and it works on my iPad.

Get Started — demyx — Code - OSS

demyxco avatar May 27 '22 06:05 demyxco

@JWleo me too and it works on my iPad.

Get Started — demyx — Code - OSS

@demyxco Then the next question is coming on ipad,HOW to make the white-line below th input-window disapper.It;s so boring! When you input through keyboard,the window will show up and push the window of code-server upper. image

JWleo avatar May 27 '22 07:05 JWleo

@JWleo I forgot to mention the powerlevel10k font isn't installed locally on the iPad. To remove that keyboard toolbar icon, go to Settings > General > Keyboard then toggle off Shortcuts and Predictive.

demyxco avatar May 27 '22 07:05 demyxco

@JWleo I forgot to mention the powerlevel10k font isn't installed locally on the iPad. To remove that keyboard toolbar icon, go to Settings > General > Keyboard then toggle off Shortcuts and Predictive.

me too. The powerlevel10k just need to install on the server-device, and you just install the fonts on your own device to call the powerlevel10k on server.

JWleo avatar May 27 '22 07:05 JWleo

@ManiaciaChao version 4.2.0, the workbench.html's path is changed: <install-path>/vendor/modules/code-oss-dev/out/vs/code/browser/workbench/workbench.html to <install-path>/lib/vscode/out/vs/code/browser/workbench/workbench.html

However, unless workbench.html's name is changed, this command might always work to load web font(Fira Code Regular). (the path of workbench.html doesn't matter!)

cd /usr/lib/code-server #my install path

#find workbench.html and add style code
find . -name workbench.html | sudo xargs sed -i "s%</head>%<style>@import url('https://fonts.googleapis.com/css2?family=Fira+Code\&display=swap');</style></head>%g"

Therefore, you can apply the font by executing this command.

cd /usr/lib/code-server #my install path

#find workbench.html and add style code
find . -name workbench.html | sudo xargs sed -i "s%</head>%<style>@import url('https://fonts.googleapis.com/css2?family=Fira+Code\&display=swap');</style></head>%g"

# update style-src
grep -rl "style-src 'self' 'unsafe-inline'" . | sudo xargs sed -i "s/style-src 'self' 'unsafe-inline'/style-src 'self' 'unsafe-inline' fonts.googleapis.com/g"
# update font-src
grep -rl "font-src 'self' blob:" . | sudo xargs sed -i "s/font-src 'self' blob:/font-src 'self' blob: fonts.gstatic.com/g"

# then restart code-server

EDIT: workbench.html's path in 4.3.0 is same as 4.2.0!

In 4.4.0, this doesn't seem to work, as vscode's iframe has a security policy that you cannot override. Any ideas?

Sharpz7 avatar Jun 01 '22 13:06 Sharpz7

@Sharpz7 - I have updated the font patch for version 4.4.0. If you don't find any solution, try mime. https://github.com/tuanpham-dev/code-server-font-patch

tuanpham-dev avatar Jun 01 '22 14:06 tuanpham-dev

Yeah this works. Thank you!

Sharpz7 avatar Jun 06 '22 16:06 Sharpz7

@JWleo me too and it works on my iPad.

Get Started — demyx — Code - OSS

How’d you get this working on the iPad?

dylanspag avatar Jul 04 '22 07:07 dylanspag

@dylanspag before you want to change the fonts of code-sever,you must change your fonts on web browser. you can get some app to install your own fonts of power10k to your ipad,and at the same time you will install the fonts on your web-browser. Then using the browser to open your code-server site.

Now you can use oh-my-zsh just like normal

JWleo avatar Jul 05 '22 05:07 JWleo

The Nginx method ain't working for me. Any help is appreciated. I am checking the index.html I am getting from the server and it is missing the link I am adding with sub_filter.

server {
	listen 8081;
	server_name pipad.local;

	location / {
		proxy_pass http://localhost:8080;

		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Host $http_host;
		proxy_set_header X-NginX-Proxy true;
		proxy_set_header Accept-Encoding gzip;

		sub_filter '</head>' '<link rel="stylesheet" type="text/css" href="/custom/fonts/index.css"></head>';
		sub_filter_once on;

		proxy_http_version 1.1;

		proxy_set_header Upgrade $http_upgrade;		
		proxy_set_header Connection "upgrade";

		proxy_redirect off;
	}			

	location /custom {
		autoindex on;
		root /var/www/code-server;
	}
}

Edit: I haven't enabled SSL yet.

ThatAnonyG avatar Jul 10 '22 10:07 ThatAnonyG

Its really insane how slow this project is to implement something or solve bugs. I have been trying to complete this setup for 2 days and every issue I came across is still unresolved even though they are so trivial. Imagine having to wait 2-3 years to get native custom font support. Even if the maintainers are busy, 3 years is just way too long. Jesus.

ThatAnonyG avatar Jul 10 '22 15:07 ThatAnonyG

Its really insane how slow this project is to implement something or solve bugs.

@ThatAnonyG You are always welcome to contribute.

I have been trying to complete this setup for 2 days and every issue I came across is still unresolved even though they are so trivial. Imagine having to wait 2-3 years to get native custom font support. Even if the maintainers are busy, 3 years is just way too long. Jesus.

There are several [working] ways to enable custom fonts.

benz0li avatar Jul 17 '22 09:07 benz0li