@@ -21,15 +21,33 @@ else:
2121 os.environ [' LEETCODE_BASE_URL' ] = ' https://leetcode.com'
2222
2323import leetcode
24+
25+ try :
26+ import keyring
27+ has_keyring = True
28+ except ImportError:
29+ has_keyring = False
2430EOF
2531
2632let s: inited = py3eval (' leetcode.inited' )
2733
34+ let s: has_keyring = py3eval (' has_keyring' )
35+
2836if g: leetcode_debug
2937 python3 leetcode.enable_logging ()
3038endif
3139
32- function ! leetcode#SignIn (ask) abort
40+ function ! s: DoSignIn (username, password) abort
41+ let expr = printf (' leetcode.signin("%s", "%s")' , a: username , a: password )
42+ let success = py3eval (expr )
43+
44+ if success
45+ echo ' Signed in as ' . a: username
46+ endif
47+ return success
48+ endfunction
49+
50+ function ! s: LegacySignIn (ask) abort
3351 if ! s: inited
3452 return v: false
3553 endif
@@ -45,13 +63,43 @@ function! leetcode#SignIn(ask) abort
4563 let password = g: leetcode_password
4664 endif
4765
48- let expr = printf ( ' leetcode.signin("%s", "%s") ' , username, password)
49- let success = py3eval ( expr )
66+ return s: DoSignIn ( username, password)
67+ endfunction
5068
51- if a: ask && success
52- echo ' succesfully signed in as ' .username
69+ function ! s: KeyringSignIn (ask) abort
70+ if ! s: inited
71+ return v: false
72+ endif
73+
74+ if g: leetcode_username != ' '
75+ let saved_password = py3eval (
76+ \ printf (' keyring.get_password("leetcode.vim", "%s")' ,
77+ \ g: leetcode_username ))
78+ else
79+ let saved_password = v: null
80+ endif
81+
82+ if a: ask || saved_password == v: null
83+ let username = input (' Username: ' , g: leetcode_username )
84+ let password = inputsecret (' Password: ' )
85+ let g: leetcode_username = username
86+ call py3eval (printf (' keyring.set_password("leetcode.vim", "%s", "%s")' ,
87+ \ username, password))
88+ redraw
89+ else
90+ let username = g: leetcode_username
91+ let password = saved_password
92+ endif
93+
94+ return s: DoSignIn (username, password)
95+ endfunction
96+
97+ function ! leetcode#SignIn (ask) abort
98+ if s: has_keyring
99+ return s: KeyringSignIn (a: ask )
100+ else
101+ return s: LegacySignIn (a: ask )
53102 endif
54- return success
55103endfunction
56104
57105function ! s: CheckSignIn () abort
@@ -75,6 +123,7 @@ function! s:SetupProblemListBuffer() abort
75123 setlocal norelativenumber
76124 setlocal nospell
77125 setlocal bufhidden = hide
126+ setlocal nowrap
78127 nnoremap <silent> <buffer> <return> :call <SID> HandleProblemListCR()<cr>
79128 nnoremap <silent> <buffer> s :call <SID> HandleProblemListS()<cr>
80129 nnoremap <silent> <buffer> r :call <SID> HandleProblemListR()<cr>
@@ -947,6 +996,7 @@ function! s:ListSubmissions(slug, refresh) abort
947996 setlocal nospell
948997 setlocal nonumber
949998 setlocal norelativenumber
999+ setlocal nowrap
9501000 nnoremap <silent> <buffer> <return> :call <SID> HandleSubmissionsCR()<cr>
9511001 nnoremap <silent> <buffer> r :call <SID> HandleSubmissionsRefresh()<cr>
9521002
0 commit comments